Skip to content

Optimize new solver unification table ops - #160801

Draft
nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:new-solver-probes
Draft

Optimize new solver unification table ops#160801
nnethercote wants to merge 2 commits into
rust-lang:mainfrom
nnethercote:new-solver-probes

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

The current code uses the ena crate in sub-optimal ways. Improving this gives big speed wins for the new trait solver on some benchmarks. Details in individual commits.

In `is_changed_arg` we do four variations on this (pseudocode-ish)
expression:
```
!(probe_value(vid) == Unknown && find(vid) == vid)
```
The first sub-expression means "the var's value is unknown" and the
second means "this var is a root". `probe_value` and `find` are both
parent-chasing operations, i.e. they duplicate some of their work.

We can instead use `try_probe_value` to do this more cheaply:
```
try_probe_value(vid) != Some(Unknown)
```
This has the identical meaning because `try_probe_value` means "get the
var's value, but only if it's a root". (Strange but fortuitous!)

There are four cases like this in `is_changed_arg`. Three of them
(int/float/const vars) are very similar to each other. The ty var case
has slightly different syntax but it's the same idea.
In this case we currently have something approximating this:
```
find(vid) != vid
```
which means "is this not a root var?"

This commit changes it to basically this:
```
!try_probe_value(vid).is_some()
```
which is equivalent but doesn't require any parent chasing.
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 9, 2026
@nnethercote

Copy link
Copy Markdown
Contributor 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 Aug 9, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 9, 2026
Optimize new solver unification table ops
@rust-bors

rust-bors Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 6faf9bb (6faf9bb85f7bc21e2a3dd05d1e5defd7b165b4a7)
Base parent: 153ecc4 (153ecc4f74035b709bb3e1eb9546f1d934865042)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (6faf9bb): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.2%, 0.5%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-6.7%, -0.7%] 10
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.3%, secondary 1.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.4%] 2
Regressions ❌
(secondary)
1.0% [0.4%, 3.1%] 19
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.3% [2.3%, 2.4%] 2

Cycles

Results (secondary -0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.5% [0.6%, 5.2%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.3% [-5.0%, -0.4%] 17
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.1%, -0.0%] 15
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 15
All ❌✅ (primary) -0.1% [-0.1%, -0.0%] 15

Bootstrap: 458.036s -> 459.953s (0.42%)
Artifact size: 398.61 MiB -> 398.55 MiB (-0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 9, 2026
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-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants