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

Tweak VecCache to improve performance #138405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 12, 2025

This has some tweaks to VecCache to improve performance.

  • It saves a compare_exchange in complete using the new put_unique function.
  • It removes bound checks on entries. These are instead checked in the slot_index_exhaustive test.
  • initialize_bucket is outlined and tuned for that.

cc @Mark-Simulacrum

@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
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 Mar 12, 2025
@Kobzol
Copy link
Contributor

Kobzol commented Mar 12, 2025

@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 Mar 12, 2025
@bors
Copy link
Contributor

bors commented Mar 12, 2025

⌛ Trying commit 00e7039 with merge 0b0612c...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 12, 2025
Tweak `VecCache` to improve performance

This has some tweaks to `VecCache` to improve performance.

- It saves a `compare_exchange` in `complete` using the new `put_unique` function.
- It removes bound checks on entries. These are instead checked in the `slot_index_exhaustive` test.
- `initialize_bucket` is outlined and tuned for that.

cc `@Mark-Simulacrum`
@bors
Copy link
Contributor

bors commented Mar 12, 2025

☀️ Try build successful - checks-actions
Build commit: 0b0612c (0b0612c92faadc7268901ca7f18b6859d25f4eba)

@rust-timer

This comment has been minimized.

}

#[cold]
fn initialize_bucket<V>(&self, bucket: &AtomicPtr<Slot<V>>) -> *mut Slot<V> {
#[inline(never)]
fn initialize_bucket<V>(bucket: &AtomicPtr<Slot<V>>, bucket_idx: usize) -> *mut Slot<V> {
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It avoids Self needing it exist when not inlined, as the needed information can be passed in registers instead.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0b0612c): 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.9% [0.2%, 1.8%] 15
Improvements ✅
(primary)
-0.4% [-0.9%, -0.2%] 140
Improvements ✅
(secondary)
-0.6% [-1.2%, -0.2%] 42
All ❌✅ (primary) -0.4% [-0.9%, -0.2%] 140

Max RSS (memory usage)

Results (primary -2.0%)

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)
-2.0% [-2.8%, -1.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.0% [-2.8%, -1.2%] 2

Cycles

Results (primary 4.1%, secondary -3.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)
6.8% [1.6%, 13.7%] 13
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.7% [-2.1%, -1.4%] 6
Improvements ✅
(secondary)
-3.1% [-3.5%, -2.5%] 3
All ❌✅ (primary) 4.1% [-2.1%, 13.7%] 19

Binary size

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

Bootstrap: 779.667s -> 779.823s (0.02%)
Artifact size: 365.24 MiB -> 365.04 MiB (-0.06%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 12, 2025
@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 12, 2025

Local results:

BenchmarkBeforeAfterBeforeAfterBeforeAfter
TimeTime%Physical MemoryPhysical Memory%Committed MemoryCommitted Memory%
🟣 clap:check1.4028s1.3962s -0.47%147.60 MiB147.57 MiB -0.02%192.07 MiB192.06 MiB -0.01%
🟣 hyper:check0.2335s0.2321s -0.58%80.01 MiB79.95 MiB -0.07%121.83 MiB121.83 MiB -0.01%
🟣 regex:check0.7944s0.7918s -0.33%108.43 MiB108.50 MiB 0.07%146.66 MiB146.80 MiB 0.09%
🟣 syn:check1.3258s1.3183s -0.57%141.93 MiB141.92 MiB -0.01%180.31 MiB180.36 MiB 0.03%
Total3.7565s3.7385s -0.48%477.97 MiB477.95 MiB -0.00%640.87 MiB641.04 MiB 0.03%
Summary1.0000s0.9951s -0.49%1 byte1.00 bytes -0.01%1 byte1.00 bytes 0.03%

Looks like something might be up with html5ever.

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 12, 2025

I can't reproduce the html5ever regression locally:

BenchmarkBeforeAfterBeforeAfterBeforeAfter
TimeTime%Physical MemoryPhysical Memory%Committed MemoryCommitted Memory%
🟣 html5ever:check0.6299s0.6256s -0.67%104.10 MiB103.98 MiB -0.11%147.54 MiB147.58 MiB 0.02%
Total0.6299s0.6256s -0.67%104.10 MiB103.98 MiB -0.11%147.54 MiB147.58 MiB 0.02%
Summary1.0000s0.9933s -0.67%1 byte1.00 bytes -0.11%1 byte1.00 bytes 0.02%

@Kobzol
Copy link
Contributor

Kobzol commented Mar 12, 2025

Cycles are noisy, although this was high above the threshold. Let's try again, just in case it was a fluke.

@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 Mar 12, 2025
@bors
Copy link
Contributor

bors commented Mar 12, 2025

⌛ Trying commit 00e7039 with merge d06bb14...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 12, 2025
Tweak `VecCache` to improve performance

This has some tweaks to `VecCache` to improve performance.

- It saves a `compare_exchange` in `complete` using the new `put_unique` function.
- It removes bound checks on entries. These are instead checked in the `slot_index_exhaustive` test.
- `initialize_bucket` is outlined and tuned for that.

cc `@Mark-Simulacrum`
@bors
Copy link
Contributor

bors commented Mar 12, 2025

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d06bb14): 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)
1.3% [0.6%, 1.8%] 10
Improvements ✅
(primary)
-0.4% [-0.9%, -0.2%] 143
Improvements ✅
(secondary)
-0.6% [-1.3%, -0.2%] 43
All ❌✅ (primary) -0.4% [-0.9%, -0.2%] 143

Max RSS (memory usage)

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

Cycles

Results (primary -1.5%, secondary -2.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)
- - 0
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) -1.5% [-1.5%, -1.5%] 1

Binary size

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

Bootstrap: 779.458s -> 779.323s (-0.02%)
Artifact size: 365.27 MiB -> 365.05 MiB (-0.06%)

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

Kobzol commented Mar 13, 2025

Looks like it was a fluke after all.

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

7 participants