This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Fixed error in passing sliced arrays via FFI #564
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR closes #538 by re-aligning buffers prior to exporting to the C data interface.
Background
Given two arrays,
a
andb
, on whicha
is sliced andb
has no validity, the computation ofequal(a, b)
is optimally done by equating the values (bitmap
) and cloning the validity ofa
.The c data interface allows arrays to be sliced at zero cost via a constant "offset", denoting by how much an array is offsetted by, but it does not allow individual bitmaps to be sliced. Consequently, implementations of the arrow format must "de-offset" the bitmaps to align them.
In the example above, this means that the validity of
a
cannot be combined with the resulting values bitmap because it has a differentoffset
. Instead, a new validity must be computed that has a zero offset (and thus aligned with the offset of the resulting values bitmap).This crate currently supports the former compute model because it tracks individual bitmap and buffer offsets. However, doing so forbids us from passing the bitmaps as is via the c data interface, as the c data interface only accepts a single offset per array (and not per buffer).
Solution
This PR de-offsets the bitmaps when they are to be passed to the C data interface, thereby delaying when to de-offset happens: at the c-data interface boundary as opposed to at every compute operation.
Note that this is a relatively small set of use-cases because most of the times the arrays are not sliced.
Alternatives
The alternative is to fallback to what other implementations do: de-offset the buffers on every operation. However, this resulted in a 15% performance drop in some of the kernels and a much more complex implementation of kernels since they all have to remember to de-offset bitmaps.