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

Tell LLVM that partition_point returns a valid fencepost #102535

Merged
merged 1 commit into from
Oct 2, 2022

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Oct 1, 2022

This was already done for a successful binary_search, but this way partition_point can get similar optimizations.

Demonstration that nightly can't do this optimization today, and leaves in the panicking path: https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e1074cd2faf5f68e49cffd728ded243a

r? @thomcc

This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.
@rustbot

This comment was marked as resolved.

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 1, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 1, 2022
@Kobzol
Copy link
Contributor

Kobzol commented Oct 1, 2022

Recently using partition_point helped the performance of rustc itself, let's see if this has any additional effect.

@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 Oct 1, 2022
@bors
Copy link
Contributor

bors commented Oct 1, 2022

⌛ Trying commit c7af338 with merge 7c6425f66f7ebc2482f0812dfe07a02a67b36030...

@scottmcm
Copy link
Member Author

scottmcm commented Oct 1, 2022

I'd be extremely surprised if this showed up in perf, since the branch is probably perfectly predicted since LLVM knows the panic is cold, and this doesn't help the line lookup case.

The following use is the kind of thing that this PR should improve, but it's probably not hot enough to show up:

let lower_bound = self.idx_sorted_by_item_key.partition_point(|&i| self.items[i].0 < key);
self.idx_sorted_by_item_key[lower_bound..].iter().map_while(move |&i| {

@bors
Copy link
Contributor

bors commented Oct 1, 2022

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

@rust-timer
Copy link
Collaborator

Queued 7c6425f66f7ebc2482f0812dfe07a02a67b36030 with parent de341fe, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7c6425f66f7ebc2482f0812dfe07a02a67b36030): comparison URL.

Overall result: ❌ regressions - no action needed

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.4% [1.2%, 1.6%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.7% [3.6%, 6.4%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 1, 2022
@Kobzol
Copy link
Contributor

Kobzol commented Oct 1, 2022

Ok, basically no changes.

@thomcc
Copy link
Member

thomcc commented Oct 2, 2022

This is great, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Oct 2, 2022

📌 Commit c7af338 has been approved by thomcc

It is now in the queue for this repository.

@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 Oct 2, 2022
@bors
Copy link
Contributor

bors commented Oct 2, 2022

⌛ Testing commit c7af338 with merge c2590e6...

@bors
Copy link
Contributor

bors commented Oct 2, 2022

☀️ Test successful - checks-actions
Approved by: thomcc
Pushing c2590e6 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 2, 2022
@bors bors merged commit c2590e6 into rust-lang:master Oct 2, 2022
@rustbot rustbot added this to the 1.66.0 milestone Oct 2, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c2590e6): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

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.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
-4.3% [-4.3%, -4.3%] 1
All ❌✅ (primary) -3.2% [-3.2%, -3.2%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Footnotes

  1. the arithmetic mean of the percent change

  2. number of relevant changes

@scottmcm scottmcm deleted the optimize-split-at-partition-point branch October 18, 2022 03:46
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…-point, r=thomcc

Tell LLVM that `partition_point` returns a valid fencepost

This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.

Demonstration that nightly can't do this optimization today, and leaves in the panicking path: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e1074cd2faf5f68e49cffd728ded243a>

r? `@thomcc`
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants