Add unsafe/unchecked slice functions#6901
Conversation
|
|
||
| /// The length of the scalar buffer, in units of `T`. | ||
| #[inline] | ||
| pub fn len_in_elements(&self) -> usize { |
There was a problem hiding this comment.
This is so the user can do their own range checking easily, and also so that the docstring for slice_unchecked has something to refer to.
We should maybe call this function len, but I went with the more explicit, since len usually means "number of bytes" in other contexts.
There was a problem hiding this comment.
The deref impl already means that x.len() returns this
|
The ticket links to https://docs.rs/arrow2/latest/src/arrow2/array/mod.rs.html#111 and states that unchecked slicing was very important. However, this PR is changing a method that has a different signature, in particular it is Do you have benchmarks? Edit: In general an over-reliance on slicing normally suggests an issue with the way a kernel has been implemented e.g. Bad Better Better Still |
|
I'll try to get you some benchmarks. The main thing we want to avoid is doing the same bounds checks twice: first before calling into After making this PR I started thinking though - and alternative is to add an API like this: that returns That way the bounds-check is only done once, though lack of inlining may still hurt perf. And yes, we have a weird usecase. We are generating code for arrow-deserialization, and the code is not pretty 😓 I'm looking deeper now to see if we can avoid all of this… converting to draft in the meantime. |
|
After some internal review it's become clear that this ugly code-generated arrow-derserialization we do is never on the fast path (anymore), so we don't need this after all. Sorry for the noise! |
### Related * Part of #3741 * ~Blocked by apache/arrow-rs#6901 * #6830 ### TODO * [x] Run `@rerun-bot full-check`
Which issue does this PR close?
Rationale for this change
Fast slicing when the user has done their own bounds checking before-hand
What changes are included in this PR?
Adds:
ScalarBuffer::new_uncheckedScalarBuffer::slice_uncheckedScalarBuffer::len_in_elementsAre there any user-facing changes?
Yes, three added methods (see above)