Repository navigation
Use iter::repeat_n to implement Vec::extend_with - #133662
paolobarbolini wants to merge 2 commits into
Conversation
|
r? @Noratrieb rustbot has assigned @Noratrieb. Use |
|
Let's see what effect this has in the compiler! |
This comment has been minimized.
This comment has been minimized.
…epeatn, r=<try> Use `iter::repeat_n` to implement `Vec::extend_with` This replaces the `Vec::extend_with` manual implementation, which is used by `Vec::resize` and `Vec` `SpecFromElem`, with `iter::repeat_n`. I've compared the codegen output between: 1. the current `Vec::resize` impl 2. this branch 3. this branch + rust-lang#130887 3 gives the closest codegen output to 1, with some output improvements. 2 doesn't look good: https://rust.godbolt.org/z/Yrc83EhjY. May also help rust-lang#120050?
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (243c5cc): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 0.1%)This 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.
CyclesResults (secondary -2.1%)This 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 sizeResults (primary 0.4%)This 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: 773.805s -> 774.205s (0.05%) |
|
Could we do another perf run? I've cherry-picked the commit from #130887 since, at least via Compiler Explorer, the codegen looked better |
|
Sure! |
This comment has been minimized.
This comment has been minimized.
…epeatn, r=<try> Use `iter::repeat_n` to implement `Vec::extend_with` This replaces the `Vec::extend_with` manual implementation, which is used by `Vec::resize` and `Vec` `SpecFromElem`, with `iter::repeat_n`. I've compared the codegen output between: 1. the current `Vec::resize` impl 2. this branch 3. this branch + rust-lang#130887 3 gives the closest codegen output to 1, with some output improvements. 2 doesn't look good: https://rust.godbolt.org/z/Yrc83EhjY. May also help rust-lang#120050? --- WARNING: DO NOT MERGE - in order to run the perf run in rust-lang#133662 (comment) this PR currently also contains commits from rust-lang#130887
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (78d5ed4): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking 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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -5.6%, secondary 0.3%)This 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.
CyclesResults (primary -1.5%, secondary 35.1%)This 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 sizeResults (primary 0.6%)This 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: 767.632s -> 769.266s (0.21%) |
|
Looking at performance data borrow checking time in the Cycles benchmark for wg-grammar is the main culprit. I'm confused why that is. The fact that this also fixes #120050 makes these changes still worth it to me. |
There was a problem hiding this comment.
I had a couple of shotgun debugging ideas -- no idea if they'll actually help, but since the perf results were still pretty red it might be good to try some stuff.
Aside, if I'm reading https://doc.rust-lang.org/nightly/std/clone/trait.TrivialClone.html right it doesn't actually say that Drop needs to be trivial? So can we just not specialize away the drop guards any more, maybe?
164c6cf to
28e44dc
Compare
|
I've made both changes. Can we rerun perf? |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…=<try> Use `iter::repeat_n` to implement `Vec::extend_with`
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (74054d7): comparison URL. Overall result: ❌ regressions - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 4.7%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 2.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.4%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 473.727s -> 474.786s (0.22%) |
This comment has been minimized.
This comment has been minimized.
|
also @paolobarbolini since "you" is not a valid way to ping people |
This replaces the manual `Vec::extend_with` implementation with `iter::repeat_n` and `Vec::extend_trusted`. This simplifies the code and gets LLVM to remove the special case for the last element when `T` is trivial to clone.
After running perf on the previous commit, it was found that the compile-time regression was too significant to ignore. This introduces a specialized, simplified implementation for `T: TrivialClone` that will reduce the perf regression.
28e44dc to
fd362c2
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I've rebased on top of main and I've run the cachegrind benchmarks locally both from the December 2025 and the current compiler, and things seem to have improved. Could we get a new perf run? |
|
☔ The latest upstream changes (presumably #165286) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
|
Can rerun perf for you after rebase since presumably rebasing might affect things. |
|
I guess someone else got to implementing this same thing, which got merged in #163757. Closing. |
|
Yeah, unfortunately these old issues only getting triaged now has lead to a few mishaps like that. Hopefully shouldn't happen as often in the future now that we've been going through the libs backlog. |
View all comments
This replaces the
Vec::extend_withmanual implementation withiter::repeat_n, simplifying the code and fixing the issue identified in #120050.