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

BTree: avoid most unsafe code in iterators #86195

Closed

Conversation

ssomers
Copy link
Contributor

@ssomers ssomers commented Jun 10, 2021

Let's see what performance we get by removing most of the _unchecked distinction in the internal iterator API, which is supposed to speed up iterators that track the remaining length while iterating and therefore never hit the "end" of a tree. We still let these iterators track remaining length because that's also needed to offer accurate size_hints to BTree clients.

The essential difference are simple null checks: we pass around Option<Handle<…>> instead of Handle<…> (where the handle has a NonNull niche).

Alloc's benchmarks are indecisive: depending on how much of these changes are considered, some benchmarks win and some loose.

r? @Mark-Simulacrum

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 10, 2021
@Mark-Simulacrum
Copy link
Member

@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 Jun 20, 2021
@bors
Copy link
Contributor

bors commented Jun 20, 2021

⌛ Trying commit f074e79158e6b8558a80dbfeae8da79d0a62ae82 with merge 402059575e35429b87602381a02705d86b3fd88b...

@bors
Copy link
Contributor

bors commented Jun 20, 2021

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

@rust-timer
Copy link
Collaborator

Queued 402059575e35429b87602381a02705d86b3fd88b with parent dd94145, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (402059575e35429b87602381a02705d86b3fd88b): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 21, 2021
@ssomers ssomers force-pushed the btree_cleanup_LeafRange_more branch 2 times, most recently from 7d8717a to 40079f6 Compare June 21, 2021 07:33
@ssomers
Copy link
Contributor Author

ssomers commented Jun 21, 2021

Performance seem to suffer a tiny bit, much less than the influence of #[inline].

Last commit is a plain rebase, but restoring the #[inline] on the public next_checked and next_back_checked functions that #85980 added. I removed those #[inline] in the original commit because the underlying unsafe functions got literally inlined in them and did not have #[inline]. Now I suspect the #[inline] matters mostly on pub functions, and the above measurement is mostly affected by the disappearance of those #[inline] just like the initial commit of #85980 was.

@Mark-Simulacrum
Copy link
Member

@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 Jun 21, 2021
@bors
Copy link
Contributor

bors commented Jun 21, 2021

⌛ Trying commit 40079f6f60f1b522b70e340353b58caafeab8f63 with merge 4ef624de06d9a49d294a504b745673d694b1885a...

@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 21, 2021
@bors
Copy link
Contributor

bors commented Jun 21, 2021

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

@rust-timer
Copy link
Collaborator

Queued 4ef624de06d9a49d294a504b745673d694b1885a with parent 9d93819, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (4ef624de06d9a49d294a504b745673d694b1885a): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@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. labels Jun 21, 2021
@JohnCSimon JohnCSimon removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2021
@JohnCSimon JohnCSimon added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 6, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 8, 2021
…p, r=Mark-Simulacrum

BTree: consistently avoid unwrap_unchecked in iterators

Some iterator support functions named `_unchecked` internally use `unwrap`, some use `unwrap_unchecked`. This PR tries settling on `unwrap`. rust-lang#86195 went up the same road but travelled way further and doesn't seem successful.

r? `@Mark-Simulacrum`
@ssomers ssomers force-pushed the btree_cleanup_LeafRange_more branch from 40079f6 to dc3c8df Compare July 8, 2021 20:26
@ssomers
Copy link
Contributor Author

ssomers commented Jul 8, 2021

Not sure this is worth the trouble but here it is rebased.

@ssomers ssomers changed the title BTree: avoid unsafe code in iterators BTree: avoid most unsafe code in iterators Jul 9, 2021
@Mark-Simulacrum
Copy link
Member

@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 Jul 10, 2021
@bors
Copy link
Contributor

bors commented Jul 10, 2021

⌛ Trying commit dc3c8df with merge f0274b9b17d524ee8d22d030f9ec8a9f95d70f29...

@bors
Copy link
Contributor

bors commented Jul 10, 2021

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

@rust-timer
Copy link
Collaborator

Queued f0274b9b17d524ee8d22d030f9ec8a9f95d70f29 with parent 432e145, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (f0274b9b17d524ee8d22d030f9ec8a9f95d70f29): comparison url.

Summary: This change led to significant regressions 😿 in compiler performance.

  • Moderate regression in instruction counts (up to 1.0% on incr-patched: println builds of cargo-opt)

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 @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 Jul 11, 2021
@ssomers
Copy link
Contributor Author

ssomers commented Jul 11, 2021

Bootstrap timing went up from 0.1% over 0.2% to 0.3% as other differences were ironed out. Is it trying to say something?

@ssomers ssomers closed this Jul 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants