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

[rustc_data_structures] Use partition_point to find slice range end. #114231

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

ttsugriy
Copy link
Contributor

@ttsugriy ttsugriy commented Jul 30, 2023

This PR uses approach introduced in #114152 to find
the end of the range. It's much easier to understand and reason about invariants of such
implementation.
Technically it's possible to make it even shorter by returning &[start..end] unconditionally
because even if searched item is not present in the slice, start and end would point at
the same index, so the range would be empty. The reason I decided not to use this shorter
implementation is because it would involve more comparisons in case there are no elements
in the slice with key equal to key.

Also, not that it matters much, but this implementation also improves perf according to the
benchmark below:
https://gist.github.com/ttsugriy/63c0ed39ae132b131931fa1f8a3dea55

The results on my M1 macbook air are:

Running benches/bin_search_slice_benchmark.rs (target/release/deps/bin_search_slice_benchmark-90fa6d68c3bd1298)
Benchmarking multiply add/binary_search_slice: Collecting 100 samples in estimated 5.0002 s (1
multiply add/binary_search_slice
                        time:   [44.719 ns 44.918 ns 45.158 ns]
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  1 (1.00%) high mild
  2 (2.00%) high severe
Benchmarking multiply add/binary_search_slice_new: Collecting 100 samples in estimated 5.0001 
multiply add/binary_search_slice_new
                        time:   [36.955 ns 37.060 ns 37.221 ns]
                        No change in performance detected.
Found 7 outliers among 100 measurements (7.00%)
  3 (3.00%) high mild
  4 (4.00%) high severe

@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 30, 2023
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Jul 31, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 31, 2023
@bors
Copy link
Collaborator

bors commented Jul 31, 2023

⌛ Trying commit 9ced089 with merge cdca3430dc0d29742e4cff0188d837a46e9a1f3d...

@bors
Copy link
Collaborator

bors commented Jul 31, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (cdca3430dc0d29742e4cff0188d837a46e9a1f3d): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
6.1% [6.1%, 6.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-0.7%, -0.4%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 652.574s -> 650.842s (-0.27%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 31, 2023
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Aug 1, 2023

This pull request seems to have regressions. Do you have any ideas to improve this? @ttsugriy

@ttsugriy
Copy link
Contributor Author

ttsugriy commented Aug 1, 2023

@TaKO8Ki , are you sure these regression numbers legit? Even if this PR had a regression, which I doubt, the magnitude seems very unlikely. Is there a way to rerun these benchmarks?

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Aug 1, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 1, 2023
@bors
Copy link
Collaborator

bors commented Aug 1, 2023

⌛ Trying commit 9ced089 with merge 539a718a86697c85050b140cfd17d0b168c1162d...

@bors
Copy link
Collaborator

bors commented Aug 1, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (539a718a86697c85050b140cfd17d0b168c1162d): comparison URL.

Overall result: no relevant changes - 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-perf -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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-3.3%, -2.3%] 4
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 649.854s -> 651.21s (0.21%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Aug 1, 2023
@ttsugriy
Copy link
Contributor Author

ttsugriy commented Aug 1, 2023

Thanks for rerunning the tests, @TaKO8Ki ! As you can see, as expected, the "regression" was just a measurement noise :)

@apiraino apiraino added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 21, 2023
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit wrt comments. r=me afterwards.

@cjgillot cjgillot assigned cjgillot and unassigned TaKO8Ki Sep 25, 2023
@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 25, 2023
@Dylan-DPC
Copy link
Member

@ttsugriy any updates on this?

@ttsugriy
Copy link
Contributor Author

ttsugriy commented Nov 5, 2023

@Dylan-DPC I don't see any comments below mine, so I guess there are no updates

@Dylan-DPC
Copy link
Member

@ttsugriy you haven't made the changes with respect to this review which is all that's left to get this pr merged

@ttsugriy
Copy link
Contributor Author

ttsugriy commented Nov 5, 2023

@Dylan-DPC the review comment didn't request any changes - it simply questioned the value of explicit invariants. I think that plain text comments are much less useful than invariants so I didn't consider that comment as a call for action. Since I no longer use Rust, I don't mind removing these useful invariants, so they are now gone.

@scottmcm scottmcm 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 15, 2024
@wesleywiser
Copy link
Member

Thanks @ttsugriy!

@bors r=cjgillot

@bors
Copy link
Collaborator

bors commented Jan 18, 2024

📌 Commit 97bc528 has been approved by cjgillot

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 Jan 18, 2024
@bors
Copy link
Collaborator

bors commented Jan 18, 2024

⌛ Testing commit 97bc528 with merge 25f8d01...

@bors
Copy link
Collaborator

bors commented Jan 18, 2024

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 25f8d01 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 18, 2024
@bors bors merged commit 25f8d01 into rust-lang:master Jan 18, 2024
@rustbot rustbot added this to the 1.77.0 milestone Jan 18, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (25f8d01): 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.7% [4.7%, 4.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 665.206s -> 666.403s (0.18%)
Artifact size: 308.34 MiB -> 308.34 MiB (-0.00%)

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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants