rust
rust copied to clipboard
internal iteration for `&mut I`
this pr implements internal iteration for &mut I when I: Sized. it additionally inlines some wrapper functions that were not previously inline, which seems to speed things up by a fair amount in some cases.
this lead to up to 3x performance gains across the board for iter:: benches, with only a minor regression for iter::bench_filter_sum
Hey! It looks like you've submitted a new PR for the library teams!
If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.
Examples of T-libs-api changes:
- Stabilizing library features
- Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
- Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
- Changing public documentation in ways that create new stability guarantees
- Changing observable runtime behavior of library APIs
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @scottmcm (or someone else) soon.
Please see the contribution instructions for more information.
@bors try @rust-timer queue
Awaiting bors try build completion.
@rustbot label: +S-waiting-on-perf
:hourglass: Trying commit cb7f7ee07f6d67e36cc08b337c034f5e81343dc1 with merge 3e685715a7ece536b2ab653e3433c06c00454bdf...
:sunny: Try build successful - checks-actions
Build commit: 3e685715a7ece536b2ab653e3433c06c00454bdf (3e685715a7ece536b2ab653e3433c06c00454bdf)
Queued 3e685715a7ece536b2ab653e3433c06c00454bdf with parent d77da9da84fc89908ad01578c33c2dca8f597ffe, future comparison URL.
Finished benchmarking commit (3e685715a7ece536b2ab653e3433c06c00454bdf): comparison url.
Instruction count
- Primary benchmarks: mixed results
- Secondary benchmarks: mixed results
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions πΏ (primary) |
0.8% | 25.3% | 66 |
| Regressions πΏ (secondary) |
0.6% | 1.9% | 32 |
| Improvements π (primary) |
-0.5% | -1.5% | 14 |
| Improvements π (secondary) |
-0.6% | -1.4% | 22 |
| All πΏπ (primary) | 0.6% | 25.3% | 80 |
Max RSS (memory usage)
Results
- Primary benchmarks: π relevant improvement found
- Secondary benchmarks: mixed results
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions πΏ (primary) |
N/A | N/A | 0 |
| Regressions πΏ (secondary) |
4.0% | 4.0% | 1 |
| Improvements π (primary) |
-2.3% | -2.3% | 1 |
| Improvements π (secondary) |
-2.5% | -2.5% | 1 |
| All πΏπ (primary) | -2.3% | -2.3% | 1 |
Cycles
Results
- Primary benchmarks: πΏ relevant regressions found
- Secondary benchmarks: πΏ relevant regressions found
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions πΏ (primary) |
14.7% | 37.5% | 3 |
| Regressions πΏ (secondary) |
2.8% | 3.0% | 2 |
| Improvements π (primary) |
N/A | N/A | 0 |
| Improvements π (secondary) |
N/A | N/A | 0 |
| All πΏπ (primary) | 14.7% | 37.5% | 3 |
[^1]: the arithmetic mean of the percent change [^2]: number of relevant changes
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.
Benchmarking 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.
@bors rollup=never @rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression
Wow, this totally changes the pattern of LTO in clap:

well, these don't look like the most promising results ^^'
Presumably this makes compilation slower, but the perf tests don't show the effect on the performance of the compiled code, right?
are there tests that do?
Other than the std benches (which aren't great) we don't have anything automated to assess runtime performance. In the rustc-perf suite check and doc builds are the closest since they don't codegen but they're probably not diverse enough.
You could try paring down the PR by splitting out some of the changes. E.g. some of the inlining in function.rs doesn't look relevant to iterators. You can also run rustc-perf locally and focus on that one benchmark, that should yield results more quickly (assuming you have a machine that can compile a stage1 rustc in a reasonable amount of time).
rustc-perf seems to take forever on my machine and i can't display the results after it's finished. so that doesn't seem like a good option for me :/
It can be set to run a subset of the benchmarks, e.g. the serde ones. https://github.com/rust-lang/rustc-perf/tree/master/collector#benchmarking-options Running the site locally should work as long as it uses the same DB as generated by the collector.
thanks for the tips! i managed to get it working thanks to your help. it seems that the biggest culprit was inlining the ops::function wrappers.
but even without it i still get a 1-2% regression on deeply-nested-multi
I'm going to send this over to
r? @m-ou-se
because I think this is going to be as much a policy decision (about compile-vs-runtime) as it is about the code itself.
Some changes were reverted, let's get new perf results.
@bors try @rust-timer queue
Awaiting bors try build completion.
@rustbot label: +S-waiting-on-perf
:hourglass: Trying commit f6a3462bda206ae937ff83760bf0d359fb2ddf0e with merge c20ee6d211784a78b94e26d37cce4e66acea976a...
:sunny: Try build successful - checks-actions
Build commit: c20ee6d211784a78b94e26d37cce4e66acea976a (c20ee6d211784a78b94e26d37cce4e66acea976a)
Queued c20ee6d211784a78b94e26d37cce4e66acea976a with parent aeb5067967ef58e4a324b19dd0dba2f385d5959f, future comparison URL.
Finished benchmarking commit (c20ee6d211784a78b94e26d37cce4e66acea976a): comparison url.
Instruction count
- Primary benchmarks: mixed results
- Secondary benchmarks: β relevant regressions found
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions β (primary) |
0.2% | 0.3% | 14 |
| Regressions β (secondary) |
0.7% | 2.0% | 16 |
| Improvements β
(primary) |
-0.4% | -0.7% | 7 |
| Improvements β
(secondary) |
- | - | 0 |
| All ββ (primary) | 0.0% | -0.7% | 21 |
Max RSS (memory usage)
Results
- Primary benchmarks: no relevant changes found
- Secondary benchmarks: mixed results
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions β (primary) |
- | - | 0 |
| Regressions β (secondary) |
2.4% | 4.5% | 8 |
| Improvements β
(primary) |
- | - | 0 |
| Improvements β
(secondary) |
-3.4% | -4.2% | 3 |
| All ββ (primary) | - | - | 0 |
Cycles
Results
- Primary benchmarks: β relevant improvement found
- Secondary benchmarks: β relevant improvement found
| mean[^1] | max | count[^2] | |
|---|---|---|---|
| Regressions β (primary) |
- | - | 0 |
| Regressions β (secondary) |
- | - | 0 |
| Improvements β
(primary) |
-2.3% | -2.3% | 1 |
| Improvements β
(secondary) |
-4.1% | -4.1% | 1 |
| All ββ (primary) | -2.3% | -2.3% | 1 |
[^1]: the arithmetic mean of the percent change [^2]: number of relevant changes
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.
Benchmarking 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.
@bors rollup=never @rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression
r? @the8472
The compile-time perf numbers are slightly negative, but less so than the previous attempt to do this.
But we need some runtime benchmark numbers to verify that it brings the expected benefits. There are some core::iter benchmarks that I'd expect to show some speedup.
@rustbot author
@sarah-ek any updates on this?
Closing this as inactive. Feel free to reΓΆpen this pr or create a new pr if you get the time to work on this. Thanks