-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[Experiment] Eliminate possible Vec::push
branches
#121300
Conversation
rustbot has assigned @Mark-Simulacrum. Use r? to explicitly pick a reviewer |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fixed it for you, it should work now |
This comment has been minimized.
This comment has been minimized.
[Experiment] Eliminate possible `Vec::push` branches Related to rust-lang#105156. Requesting a perf run. ```rust pub fn push(v: &mut Vec<u8>) { let _ = v.reserve(4); v.push(1); v.push(2); v.push(3); v.push(4); } ``` AFAICT, the codegen backend should infer the infallibility of these `push`s but unfortunately with LLVM 18 we still have unnecessary `reserve_for_push` branches. For the sake of curiosity, `assert_unchecked` was included in `push` to see any potential impact of such change. Take a look at the generated assembly at https://godbolt.org/z/b5jjPhsf8. AFAICT (again), the assumption of more available capacity for each `push` is not valid for all situations.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (ba16851): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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: 641.758s -> 640.665s (-0.17%) |
Thanks @Nilstrieb |
@@ -1925,6 +1929,7 @@ impl<T, A: Allocator> Vec<T, A> { | |||
let end = self.as_mut_ptr().add(self.len); | |||
ptr::write(end, value); | |||
self.len += 1; |
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.
Just as a note: LLVM's constraint elimination can work better when this is written as:
// rustc emits: `add nuw`, so the pass can assume that the instruction does not overflow
self.len = unsafe { self.len.unchecked_add(1) };
This reduces some calls to reserve_for_push
but does not eliminate all of them. I haven't really had the time to dig in further to find out...
Related to #105156. Requesting a perf run.
AFAICT, the codegen backend should infer the infallibility of these
push
s but unfortunately with LLVM 18 we still have unnecessaryreserve_for_push
branches.For the sake of curiosity,
assert_unchecked
was included inpush
to see any potential impact of such change. Take a look at the generated assembly at https://godbolt.org/z/b5jjPhsf8.AFAICT (again), the assumption of more available capacity for each
push
is not valid for all situations.