-
Notifications
You must be signed in to change notification settings - Fork 821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
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_unchecked
ScalarBuffer::slice_unchecked
ScalarBuffer::len_in_elements
Are there any user-facing changes?
Yes, three added methods (see above)