-
Notifications
You must be signed in to change notification settings - Fork 112
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
Benchmark and optimize PyArray2/3::from_vec2/3 #292
Conversation
65e4654
to
7bd0630
Compare
Not doing an upfront pass to check for ragged arrays brings another single digit percentage win:
|
6664de8
to
d384132
Compare
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 plus #291 is very cool - always nice to deliver performance improvements! Just a few random thoughts.
src/array.rs
Outdated
assert!(idx == len); | ||
array | ||
} | ||
let data = iter.collect::<Box<[_]>>(); |
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.
It looks like the implementation for FromIterator
for boxed slices just goes through Vec
anyway, so do we really need the from_exact_iter
variant?
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.
My initial aim was to avoid changing the API, but since from_*iter
is probably not the most used API and we are still at version 0.x, this does not really seem to be appropriate.
As for using Box<[_]>
instead of Vec<_>
, I was thinking that the exact case will not end up with excess capacity and hence could go from vec to boxed slice without re-allocation. But this is not really useful as a boxed slice and a vec without excess capacity will basically end up creating the same PySliceContainer
instance.
Hence, I'll add a commit removing the from_exact_iter
method as any specializations that the standard library provides with pass through the generic signature of from_iter
in any case.
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.
@davidhewitt Please let me know if changing API is alright without before I merge. Thanks!
d273589
to
4c89dee
Compare
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.
Happy with this as-is, though I do prefer deprecating where possible myself.
…array for from_vec2/3.
…se it in PyArray::from_slice/vec2/vec3.
… on top of PyArray::from_iter.
4c89dee
to
0b3a83e
Compare
Follow-up to #291. Admittedly, performance conscious code will probably try to avoid these methods, but it is relatively straight-forward to optimize them, as using pointer traversal instead of indexing brings a large improvement
and optimizing for
T::IS_COPY
elements is then a bit of a mixed bag on top of thisI suspect that this is due to the innermost slices being too short for the overhead of calling
ptr::copy_nonoverlapping
to amortize itself, but I think we can still keep as it not making things significantly worse and might help in specific cases of large rows and should not add code bloat due toT::IS_COPY
being resolved at compile time.