Skip to content

Simplify and optimize VecCache's SlotIndex::from_index #142095

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

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

Conversation

joshtriplett
Copy link
Member

@joshtriplett joshtriplett commented Jun 5, 2025

Simplify and optimize SlotIndex::from_index

Break out bucket 0 (containing idx < 4096) as an early return, which
simplifies the remainder of the function, and allows optimizing the
checked_ilog2 since it can no longer return None.

This reduces the runtime of vec_cache::tests::slot_index_exhaustive
(which calls SlotIndex::from_index for every u32, twice) from ~15.5s
to ~13.3s.

Separately, simplify the test case as well. (The old and new code passes with
the old and new test case.)


Noticed because slot_index_exhaustive stood out as taking unusually long compared to other tests, so I started investigating what it was doing.

Break out bucket 0 (containing `idx < 4096`) as an early return, which
simplifies the remainder of the function, and allows optimizing the
`checked_ilog2` since it can no longer return `None`.

This reduces the runtime of `vec_cache::tests::slot_index_exhaustive`
(which calls `SlotIndex::from_index` for every `u32`, twice) from ~15.5s
to ~13.3s.
`slot_index_exhaustive` has additional complexity in its loop that only
applies for index 0. Pull that case out of the loop.
@rustbot
Copy link
Collaborator

rustbot commented Jun 5, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jun 5, 2025
@joshtriplett
Copy link
Member Author

@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 Jun 5, 2025
bors added a commit that referenced this pull request Jun 5, 2025
Simplify and optimize `VecCache`'s `SlotIndex::from_index`

Simplify and optimize `SlotIndex::from_index`

Break out bucket 0 (containing `idx < 4096`) as an early return, which
simplifies the remainder of the function, and allows optimizing the
`checked_ilog2` since it can no longer return `None`.

This reduces the runtime of `vec_cache::tests::slot_index_exhaustive`
(which calls `SlotIndex::from_index` for every `u32`, twice) from ~15.5s
to ~13.3s.

Separately, simplify the test case as well. (The old and new code passes with
the old and new test case.)
@bors
Copy link
Collaborator

bors commented Jun 5, 2025

⌛ Trying commit 9837c3c with merge 18aa6ca...

@bors
Copy link
Collaborator

bors commented Jun 5, 2025

☀️ Try build successful - checks-actions
Build commit: 18aa6ca (18aa6ca8c951e4ad5d9c94ee7ae3af8c80e4d939)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (18aa6ca): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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 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.3% [0.2%, 0.5%] 4
Improvements ✅
(primary)
-0.8% [-3.4%, -0.1%] 194
Improvements ✅
(secondary)
-1.0% [-4.7%, -0.1%] 105
All ❌✅ (primary) -0.8% [-3.4%, -0.1%] 194

Max RSS (memory usage)

Results (primary 1.0%, secondary -5.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)
1.0% [1.0%, 1.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.1% [-8.0%, -1.3%] 10
All ❌✅ (primary) 1.0% [1.0%, 1.0%] 1

Cycles

Results (primary -1.6%, secondary -0.8%)

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)
6.3% [5.9%, 6.7%] 2
Improvements ✅
(primary)
-1.6% [-2.0%, -1.1%] 2
Improvements ✅
(secondary)
-3.2% [-3.9%, -2.3%] 6
All ❌✅ (primary) -1.6% [-2.0%, -1.1%] 2

Binary size

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

Bootstrap: 750.971s -> 749.964s (-0.13%)
Artifact size: 371.78 MiB -> 371.52 MiB (-0.07%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 6, 2025
Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

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

The result looks very nice!

@nnethercote
Copy link
Contributor

@SparrowLii: you gave approval in the GitHub review, do you want to give r+? I'm happy with how the PR looks.

@SparrowLii
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 6, 2025

📌 Commit 8a56ed4 has been approved by SparrowLii

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 Jun 6, 2025
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-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.

6 participants