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

valtree performance tuning #136593

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

Conversation

lukas-code
Copy link
Member

@lukas-code lukas-code commented Feb 5, 2025

Summary: This PR makes type checking of code with many type-level constants faster.

After #136180 was merged, we observed a small perf regression (#136318 (comment)). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates:

ty::ConstKind::Value(lhs_val) => match rhs.kind() {
ty::ConstKind::Value(rhs_val) => lhs_val.valtree() == rhs_val.valtree(),

This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with feature(adt_const_params), so the fast reject code doesn't have to do a deep compare of the valtrees.

A less invasive alternative that I considered is simply avoiding copies introduced by #136180 and comparing the valtrees it in-place (see commit: 9e91e50 / perf results: #136593 (comment)), however that was still measurably slower than interning.

@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 Feb 5, 2025
@lukas-code
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 Feb 5, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2025
[perf] try to mitigate regression in fast reject for `ty::Value`

rust-lang#136318 (comment)

r? ghost
@bors
Copy link
Contributor

bors commented Feb 5, 2025

⌛ Trying commit dc8caa3 with merge 95bc439...

@bors
Copy link
Contributor

bors commented Feb 5, 2025

☀️ Try build successful - checks-actions
Build commit: 95bc439 (95bc439e0cc5e28a3a245d530f8acb3b84d250ac)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (95bc439): 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 (primary -2.0%, 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)
6.3% [6.3%, 6.3%] 1
Improvements ✅
(primary)
-2.0% [-2.0%, -2.0%] 1
Improvements ✅
(secondary)
-3.5% [-3.8%, -3.4%] 3
All ❌✅ (primary) -2.0% [-2.0%, -2.0%] 1

Cycles

Results (secondary 2.5%)

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.5% [2.5%, 2.5%] 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: 778.541s -> 779.446s (0.12%)
Artifact size: 328.82 MiB -> 328.84 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 6, 2025
@lukas-code
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 Feb 7, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2025
[perf] try to mitigate regression in fast reject for `ty::Value`

rust-lang#136318 (comment)

r? ghost
@bors
Copy link
Contributor

bors commented Feb 7, 2025

⌛ Trying commit bc51bb2 with merge 9e91e50...

@bors
Copy link
Contributor

bors commented Feb 7, 2025

☀️ Try build successful - checks-actions
Build commit: 9e91e50 (9e91e50ac5920f0b9b4a3b1e0880c85336ba5c64)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9e91e50): 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)
-1.6% [-2.6%, -0.1%] 14
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) -1.6% [-2.6%, -0.1%] 14

Max RSS (memory usage)

Results (primary -0.9%, secondary -2.5%)

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.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.0% [-3.0%, -3.0%] 1
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.5%] 1
All ❌✅ (primary) -0.9% [-3.0%, 1.1%] 2

Cycles

Results (primary -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)
-2.1% [-3.0%, -1.6%] 9
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.1% [-3.0%, -1.6%] 9

Binary size

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

Bootstrap: 780.473s -> 782.144s (0.21%)
Artifact size: 329.02 MiB -> 328.96 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 7, 2025
@rustbot rustbot added the A-rustc-dev-guide Area: rustc-dev-guide label Feb 7, 2025
@lukas-code
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 Feb 7, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2025
[perf] try to mitigate regression in fast reject for `ty::Value`

rust-lang#136318 (comment)

r? ghost
@bors
Copy link
Contributor

bors commented Feb 7, 2025

⌛ Trying commit cd733ad with merge b50e910...

@rust-log-analyzer

This comment has been minimized.

@lukas-code
Copy link
Member Author

lukas-code commented Feb 7, 2025

@rust-timer build b50e910

@rust-timer
Copy link
Collaborator

Error occurred while parsing comment: Invalid command argument b50e910b6edc6d2acb791008b59627f355c12932 (there may be no spaces around the = character)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b50e910): 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)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
0.3% [0.2%, 0.6%] 7
Improvements ✅
(primary)
-2.5% [-5.6%, -0.2%] 21
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.2% [-5.6%, 2.7%] 22

Max RSS (memory usage)

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

Cycles

Results (primary -2.8%, secondary 2.3%)

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)
2.5% [2.5%, 2.5%] 1
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
-3.2% [-5.4%, -2.2%] 16
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-5.4%, 2.5%] 17

Binary size

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

Bootstrap: 779.143s -> 777.841s (-0.17%)
Artifact size: 329.04 MiB -> 328.98 MiB (-0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 8, 2025
@bors
Copy link
Contributor

bors commented Feb 9, 2025

☔ The latest upstream changes (presumably #136762) made this pull request unmergeable. Please resolve the merge conflicts.

@lukas-code lukas-code changed the title [perf] try to mitigate regression in fast reject for ty::Value valtree performance tuning Feb 9, 2025
@lukas-code
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 Feb 9, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2025
valtree performance tuning

Summary: This PR makes type checking of code with many type-level constants faster.

After rust-lang#136180 was merged, we observed a small perf regression (rust-lang#136318 (comment)). This happened because that PR introduced additional copies in the fast reject code path for consts, which is very hot for certain crates: https://github.com/rust-lang/rust/blob/6c1d960d88dd3755548b3818630acb63fa98187e/compiler/rustc_type_ir/src/fast_reject.rs#L486-L487

This PR improves the performance again by properly interning the valtrees so that copying and comparing them becomes faster. This will become especially useful with `feature(adt_const_params)`, so the fast reject code doesn't have to do a deep compare of the valtrees.

A less invasive alternative that I considered is simply avoiding copies introduced by rust-lang#136180 and comparing the valtrees it in-place (see commit: rust-lang@9e91e50 / perf results: rust-lang#136593 (comment)), however that was still measurably slower than interning.
@bors
Copy link
Contributor

bors commented Feb 9, 2025

⌛ Trying commit d6f5175 with merge fdc99c9...

@bors
Copy link
Contributor

bors commented Feb 9, 2025

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fdc99c9): 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.4% [0.2%, 0.5%] 5
Improvements ✅
(primary)
-2.7% [-5.7%, -0.2%] 20
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) -2.7% [-5.7%, -0.2%] 20

Max RSS (memory usage)

Results (primary -1.2%, secondary 2.3%)

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

Cycles

Results (primary -3.1%, secondary 2.7%)

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.7% [2.3%, 3.1%] 2
Improvements ✅
(primary)
-3.1% [-6.1%, -1.9%] 19
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.1% [-6.1%, -1.9%] 19

Binary size

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

Bootstrap: 779.273s -> 777.952s (-0.17%)
Artifact size: 329.09 MiB -> 329.05 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustc-dev-guide Area: rustc-dev-guide 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.

5 participants