-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
BTreeMap/BTreeSet::from_iter: use bulk building to improve the performance #88448
Conversation
Bulk building is a common technique to increase the performance of building a fresh btree map. Instead of inserting items one-by-one, we sort all the items beforehand then create the BtreeMap in bulk.
Apply the same optimization as BTreeMap::from_iter.
(rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue Generally this seems OK, though I am mildly wary of the added code complexity. I don't think it's anything too worrisome though and in practice sorting is not typically that complicated. |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit a03287b with merge 86a2710516f1f19a00691b2c64e6567ecbadca63... |
☀️ Try build successful - checks-actions |
Queued 86a2710516f1f19a00691b2c64e6567ecbadca63 with parent 226e181, future comparison URL. |
Finished benchmarking try commit (86a2710516f1f19a00691b2c64e6567ecbadca63): comparison url. Summary: This change led to large relevant mixed results 🤷 in compiler performance.
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 perf run, please indicate this with @bors rollup=never |
It looks like the added codegen for BTree is increasing the work LLVM needs to do by a good bit -- 4.6% is fairly sizeable. While this does increase the performance of long iterators collecting into BTree's, I'm not sure it is worth the compile time cost here. That said, ultimately, it seems like the code being added by this PR isn't doing anything too interesting or unexpected, so I am generally inclined to move forward. The runtime performance improvement is pretty nice. So, I'm going to say that this regression is justified -- we are improving the runtime performance, and the regression appears to be entirely due to more codegen. @rustbot label: +perf-regression-triaged @bors r+ |
📌 Commit a03287b has been approved by |
☀️ Test successful - checks-actions |
As predicted, during weekly performance triage this was tagged as causing mixed changes to rustc instruction counts. Its already been appropriately labelled; I'm just adding the link above for ease of reference in future. |
Sounds like |
…8472 BTreeSet: avoid intermediate sorting when collecting sorted iterators As [pointed out by droundy](https://users.rust-lang.org/t/question-about-btreeset-implementation/76427), an obvious optimization is to skip the first step introduced by rust-lang#88448 (creation of a vector and sorting) and it's easy to do so for btree's own iterators. Also, exploit `from` in the examples.
Bulk building is a common technique to increase the performance of building a fresh btree map. Instead of inserting items one-by-one, we sort all the items beforehand then create the BtreeMap in bulk.
Benchmark