Skip to content
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

Improve capacity estimation in Vec::from_iter #92138

Merged
merged 1 commit into from
Jan 20, 2022
Merged

Improve capacity estimation in Vec::from_iter #92138

merged 1 commit into from
Jan 20, 2022

Conversation

AngelicosPhosphoros
Copy link
Contributor

@AngelicosPhosphoros AngelicosPhosphoros commented Dec 20, 2021

Iterates on the attempt made in #53086.

Closes #48994

@rust-highfive
Copy link
Collaborator

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 20, 2021
@AngelicosPhosphoros
Copy link
Contributor Author

Could someone kindly start perf after tests, please?

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 20, 2021
@bors
Copy link
Contributor

bors commented Dec 20, 2021

⌛ Trying commit a4c2147044c91d967a24983e6f39e42d1f259c02 with merge d9b995d978da72c2e7147d41e7c4a4a8369ef452...

@bors
Copy link
Contributor

bors commented Dec 20, 2021

☀️ Try build successful - checks-actions
Build commit: d9b995d978da72c2e7147d41e7c4a4a8369ef452 (d9b995d978da72c2e7147d41e7c4a4a8369ef452)

@rust-timer
Copy link
Collaborator

Queued d9b995d978da72c2e7147d41e7c4a4a8369ef452 with parent 23f6923, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d9b995d978da72c2e7147d41e7c4a4a8369ef452): comparison url.

Summary: This change led to moderate relevant improvements 🎉 in compiler performance.

  • Moderate improvement in instruction counts (up to -2.5% on incr-patched: println builds of regression-31157)

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 led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2021
@AngelicosPhosphoros
Copy link
Contributor Author

I updated PR.
I hope, this guesses are better.

May someone start perf again?

@jyn514
Copy link
Member

jyn514 commented Dec 21, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2021
@bors
Copy link
Contributor

bors commented Dec 21, 2021

⌛ Trying commit ee6b70e746897bdd0ca0c54623ddc9415edc1391 with merge 295c663aa9e8675abae1f4c4781b0e4d1a10b930...

@bors
Copy link
Contributor

bors commented Dec 21, 2021

☀️ Try build successful - checks-actions
Build commit: 295c663aa9e8675abae1f4c4781b0e4d1a10b930 (295c663aa9e8675abae1f4c4781b0e4d1a10b930)

@rust-timer
Copy link
Collaborator

Queued 295c663aa9e8675abae1f4c4781b0e4d1a10b930 with parent 3d57c61, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (295c663aa9e8675abae1f4c4781b0e4d1a10b930): comparison url.

Summary: This change led to large relevant mixed results 🤷 in compiler performance.

  • Large improvement in instruction counts (up to -2.3% on full builds of issue-46449)
  • Small regression in instruction counts (up to 2.2% on incr-patched: println builds of regression-31157)

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 led 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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 21, 2021
@AngelicosPhosphoros
Copy link
Contributor Author

I am curious, how my PR with added code can lower instruction count? What instruction count means?

@Kobzol
Copy link
Contributor

Kobzol commented Dec 21, 2021

Instruction count here means how many instructions were actually executed when compiling a specific crate with specific settings (incremental/non-incremental, check/debug/opt etc.). Lower instruction count usually means faster compile times, so this is actually a good thing!

Since your change only modifies library code, the results seem to hint that it indeed sped up Vec collection, which could translate to nice speedups not only for Rustc compile times, but also for the runtime of all Rust programs!

@AngelicosPhosphoros
Copy link
Contributor Author

Oh, that's nice.

However, I wonder why walltime for match-stress-exhaustive_patterns opt increased by 7.46% link.

Also bootstrap times increased too (maybe because there are a lot of code which collects to Vec and I increased amount of code to instantiate in each case?).

@Kobzol
Copy link
Contributor

Kobzol commented Dec 21, 2021

Bootstrap is a bit noisy, unless it regresses for +10% or something, it should be fine I think. Wall times are also extremely noisy in general, this one incr-unchanged looks like noise.

@AngelicosPhosphoros
Copy link
Contributor Author

JFYI: I wouldn't be able to participate until 15th January. I would return to this PR after that if needed.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 17, 2022
@bors
Copy link
Contributor

bors commented Jan 17, 2022

⌛ Trying commit 647ac3528a7e4c81c36d24b123d8f32b70e29f55 with merge d499522b3e906fe5c31337590db9d0564b717e42...

@bors
Copy link
Contributor

bors commented Jan 17, 2022

☀️ Try build successful - checks-actions
Build commit: d499522b3e906fe5c31337590db9d0564b717e42 (d499522b3e906fe5c31337590db9d0564b717e42)

@rust-timer
Copy link
Collaborator

Queued d499522b3e906fe5c31337590db9d0564b717e42 with parent a34c079, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d499522b3e906fe5c31337590db9d0564b717e42): comparison url.

Summary: This change led to large relevant improvements 🎉 in compiler performance.

  • Large improvement in instruction counts (up to -2.9% on full builds of issue-46449 doc)

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 led to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jan 17, 2022
@Mark-Simulacrum
Copy link
Member

If you could summarize the perf results across the runs so that we can make an informed decision as to which variant to use, that would be good.

@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 18, 2022
@AngelicosPhosphoros
Copy link
Contributor Author

It seems that last results are best. They don't have any regressions unlike first perf and have better improves than second one.

@Mark-Simulacrum Mark-Simulacrum changed the title Try to make some guesses about capacity in Vec::from_iter Improve capacity estimation in Vec::from_iter Jan 18, 2022
@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 18, 2022
@Mark-Simulacrum
Copy link
Member

@bors r+

Thanks -- squashed the commits and approving.

@bors
Copy link
Contributor

bors commented Jan 19, 2022

📌 Commit ea570c6 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2022
@bors
Copy link
Contributor

bors commented Jan 20, 2022

⌛ Testing commit ea570c6 with merge 74fbbef...

@bors
Copy link
Contributor

bors commented Jan 20, 2022

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 74fbbef to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 20, 2022
@bors bors merged commit 74fbbef into rust-lang:master Jan 20, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 20, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (74fbbef): comparison url.

Summary: This change led to large relevant improvements 🎉 in compiler performance.

  • Large improvement in instruction counts (up to -3.0% on full builds of projection-caching doc)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@AngelicosPhosphoros AngelicosPhosphoros deleted the try_smarter_vec_from_iter_48994_2 branch January 20, 2022 13:54
@dylni
Copy link
Contributor

dylni commented Apr 9, 2022

From testing, this doesn't appear to fix #48994. The lower size hint is still ignored, even though a higher initial capacity is now reserved. Can that issue be reopened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collecting into a Result<Vec<_>> doesn't reserve the capacity in advance
10 participants