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

VecDeque::partition_point and binary_search_by check first element in back slice only once #136159

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

urben1680
Copy link

@urben1680 urben1680 commented Jan 27, 2025

I noticed that the first element of the back slice is potentially checked twice for the partition_point method, first in an if-condition and second inside the respective body.

EDIT: Applied the same change to binary_search_by method.

In this change, the back slice is reduced by the first element and this offset is added to the result.

I am not sure how to trigger benchmarks for this, I assume doing this PR is the way to go for Bors.

Please tell me if this is not how pull requests should be done.

… once

I noticed that the first element of the `back` slice is potentially checked twice for the `partition_point` method, first in an if-condition and second inside the respective body.

In this change, the back slice is reduced by the first element and this offset is added to the result.

I am not sure how to trigger benchmarks for this, I assume doing this PR is the way to go for bors.

Please tell me if this is not how pull requests should be done.
@rustbot
Copy link
Collaborator

rustbot commented Jan 27, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ibraheemdev (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 27, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2025
…on-point-optimization, r=<try>

`VecDeque::partition_point` checks first element in `back` slice only once

I noticed that the first element of the back slice is potentially checked twice for the partition_point method, first in an if-condition and second inside the respective body.

In this change, the back slice is reduced by the first element and this offset is added to the result.

I am not sure how to trigger benchmarks for this, I assume doing this PR is the way to go for Bors.

Please tell me if this is not how pull requests should be done.
@bors
Copy link
Contributor

bors commented Jan 28, 2025

⌛ Trying commit 6c3de4f with merge d1b4408...

@ibraheemdev
Copy link
Member

@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 Jan 28, 2025
@bors
Copy link
Contributor

bors commented Jan 28, 2025

⌛ Trying commit 6c3de4f with merge 7ec1805...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2025
…on-point-optimization, r=<try>

`VecDeque::partition_point` checks first element in `back` slice only once

I noticed that the first element of the back slice is potentially checked twice for the partition_point method, first in an if-condition and second inside the respective body.

In this change, the back slice is reduced by the first element and this offset is added to the result.

I am not sure how to trigger benchmarks for this, I assume doing this PR is the way to go for Bors.

Please tell me if this is not how pull requests should be done.
@bors
Copy link
Contributor

bors commented Jan 28, 2025

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7ec1805): comparison URL.

Overall result: ✅ improvements - 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 is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (primary -0.7%, secondary 1.1%)

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)
1.1% [1.1%, 1.1%] 1
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-0.7%, -0.7%] 1

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: 772.605s -> 770.21s (-0.31%)
Artifact size: 328.25 MiB -> 328.30 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 28, 2025
@urben1680
Copy link
Author

urben1680 commented Jan 29, 2025

This seems to look good.

I noticed the same thing can be done to binary_search_by, I will add that too.

@urben1680 urben1680 changed the title VecDeque::partition_point checks first element in back slice only once VecDeque::partition_point and binary_search_by check first element in back slice only once Jan 30, 2025
@urben1680
Copy link
Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 30, 2025

@urben1680: 🔑 Insufficient privileges: not in try users

@ibraheemdev
Copy link
Member

@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 Jan 31, 2025
@bors
Copy link
Contributor

bors commented Jan 31, 2025

⌛ Trying commit a12248c with merge 902ee03...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 31, 2025
…on-point-optimization, r=<try>

`VecDeque::partition_point` and `binary_search_by` check first element in `back` slice only once

I noticed that the first element of the back slice is potentially checked twice for the partition_point method, first in an if-condition and second inside the respective body.

EDIT: Applied the same change to `binary_search_by` method.

In this change, the back slice is reduced by the first element and this offset is added to the result.

I am not sure how to trigger benchmarks for this, I assume doing this PR is the way to go for Bors.

Please tell me if this is not how pull requests should be done.
@bors
Copy link
Contributor

bors commented Jan 31, 2025

☀️ Try build successful - checks-actions
Build commit: 902ee03 (902ee03616c2e1f1579ac7b7369a1fa37693cdef)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (902ee03): 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)

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

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: 777.277s -> 779.692s (0.31%)
Artifact size: 328.97 MiB -> 328.96 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 31, 2025
@urben1680
Copy link
Author

So it looks like partition_point has positive effects but binary_search_by has negative and they cancel each other out together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants