-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Avoid more NonNull-raw-NonNull roundtrips in Vec #123835
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Avoid more NonNull-raw-NonNull roundtrips in Vec r? the8472 The standard library in general has a lot of these round-trips from niched types to their raw innards and back. Such round-trips have overhead in debug builds since rust-lang#120594. I removed some such round-trips in that initial PR and I've been meaning to come back and hunt down more such examples (this is the last item on rust-lang#120848).
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (7d882e6): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 676.479s -> 675.803s (-0.10%) |
e4c567e
to
e575007
Compare
This comment has been minimized.
This comment has been minimized.
e575007
to
0f2d18f
Compare
Binary sizes seem to be a wash. Instructions improvements are extremely tiny, below individual significance thresholds. Wall-times look positive but that's just reverting a spike from the previous run. From the PR description it sounds like bigger improvements were expected. |
Sorry I gave that impression. The entire envelope here if precondition checks were reduced to 0 is 1.7% in instruction count, and this change reduces the number of precondition checks in a full build of If you only want to merge this if it provides measurable perf changes on its own, I could sit on this until I can bundle it with a lot of other unrelated changes so that in total they are measurable. I don't like working that way but I know some people prefer it. |
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.
No, it's fine, I misunderstood the expectation then. The results aren't negative.
Just a few minor things then
@@ -259,6 +259,11 @@ impl<T, A: Allocator> RawVec<T, A> { | |||
Self { ptr: unsafe { Unique::new_unchecked(ptr) }, cap, alloc } | |||
} | |||
|
|||
pub(crate) unsafe fn from_nonnull_in(ptr: NonNull<T>, capacity: usize, alloc: A) -> Self { |
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's an unsafe method, so it should at least point to its sibling regarding the Safety section.
|
||
#[inline] | ||
#[cfg(not(no_global_oom_handling))] // required by tests/run-make/alloc-no-oom-handling | ||
pub(crate) unsafe fn from_nonnull(ptr: NonNull<T>, length: usize, capacity: usize) -> Self { |
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.
Ditto about Safety section/reference to sibling method.
let Ok(reallocated) = result else { handle_alloc_error(new_layout) }; | ||
dst_buf = reallocated.as_ptr() as *mut T; | ||
dst_buf = reallocated.cast(); |
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.
Can you add the <T>
? Since this method deals with an input and an output type it's nice to have those little reminders with which one of the two we're dealing again in various places.
0f2d18f
to
f7d54fa
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.
@bors r+ rollup
looks like the bot doesn't read review comments. @bors r+ rollup |
Rollup of 4 pull requests Successful merges: - rust-lang#123835 (Avoid more NonNull-raw-NonNull roundtrips in Vec) - rust-lang#123868 (Stabilize (const_)slice_ptr_len and (const_)slice_ptr_is_empty_nonnull) - rust-lang#123872 (Fix Pietro's entry in the mailmap) - rust-lang#123873 (Merge cuviper in the mailmap) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#123835 - saethlin:vec-from-nonnull, r=the8472 Avoid more NonNull-raw-NonNull roundtrips in Vec r? the8472 The standard library in general has a lot of these round-trips from niched types to their raw innards and back. Such round-trips have overhead in debug builds since rust-lang#120594. I removed some such round-trips in that initial PR and I've been meaning to come back and hunt down more such examples (this is the last item on rust-lang#120848).
r? the8472
The standard library in general has a lot of these round-trips from niched types to their raw innards and back. Such round-trips have overhead in debug builds since #120594. I removed some such round-trips in that initial PR and I've been meaning to come back and hunt down more such examples (this is the last item on #120848).