Skip to content

New solver opts for diesel - #163981

Open
nnethercote wants to merge 6 commits into
rust-lang:mainfrom
nnethercote:diesel-opts-1
Open

nnethercote wants to merge 6 commits into
rust-lang:mainfrom
nnethercote:diesel-opts-1

Conversation

@nnethercote

@nnethercote nnethercote commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

A collection of small optimizations. Details in individual commits.

Local measurements:

solver         icounts (B)
------         -----------
old            37.9
new (orig)     56.4 (1.49x)
new (this PR)  49.5 (1.31x)

Also some small improvements on a range of other benchmarks.

r? @jdonszelmann

The rust-analyzer impls of these methods will need to be removed on the
next sync.
It's faster than `extend` to initialize these structures.
A lot of work can be skipped if the two values being related are equal.
(There are various early-return equality checks like this further down
the call chain, this just adds one earlier.)
The former has an early return check and a single call site, so the
check can be moved before the call site. Also, in the `Err(NoSolution)`
case we can skip the `CandidateHeadUsages::default()` stuff because
that's just an empty list and `merge_usages` is a no-op.
Instead of getting it within `fast_reject_assumption`.

`fast_reject_assumption` has three call sites. For two of them this
change doesn't help perf, but the third call occurs in a loop, and this
lets us get the goal lang item once per loop instead of once per loop
element.
- Increase the number of preinterned type vars and anon bound types.
- Preintern some root-universe placeholder types with anon bounds.
- Adjust some comments.
- Also rename a lot of the preinterning names for more consistency.
@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 Oct 8, 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 Oct 8, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 8, 2026
@rust-bors

rust-bors Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 72d027b (72d027b9aaffb1bdcbbb7a99d0fa20cbfe294b2c)
Base parent: fc2324d (fc2324d0546aa6782c45b76247266a0c37db0b8a)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (72d027b): 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.4% [0.2%, 0.6%] 6
Regressions ❌
(secondary)
0.3% [0.1%, 0.4%] 3
Improvements ✅
(primary)
-0.2% [-0.5%, -0.1%] 9
Improvements ✅
(secondary)
-1.1% [-11.1%, -0.1%] 55
All ❌✅ (primary) 0.0% [-0.5%, 0.6%] 15

Max RSS (memory usage)

Results (primary -2.7%, secondary 2.6%)

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

mean range count
Regressions ❌
(primary)
0.7% [0.7%, 0.7%] 1
Regressions ❌
(secondary)
5.1% [2.3%, 7.0%] 3
Improvements ✅
(primary)
-6.1% [-6.1%, -6.1%] 1
Improvements ✅
(secondary)
-4.9% [-4.9%, -4.9%] 1
All ❌✅ (primary) -2.7% [-6.1%, 0.7%] 2

Cycles

Results (primary 2.4%, secondary -1.1%)

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

mean range count
Regressions ❌
(primary)
2.4% [2.1%, 2.6%] 2
Regressions ❌
(secondary)
3.9% [2.5%, 7.5%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.2% [-7.1%, -5.7%] 4
All ❌✅ (primary) 2.4% [2.1%, 2.6%] 2

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 484.956s -> 485.101s (0.03%)
Artifact size: 406.45 MiB -> 406.59 MiB (0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 8, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: some of these changes were based on ideas from LLM analysis of profiles. I wrote the code and text myself.

@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

@nnethercote

Copy link
Copy Markdown
Contributor Author

The perf results show big wins for diesel and smaller wins for some other benchmarks, including some new solver ones. There are very small regressions on helloworld and a couple of other very short-running benchmarks due to preinterning more values at startup. I already tweaked the amount of interning to get a good balance here; I think a tiny bit of red is worth it for the additional green on the new solver benchmarks.

@nnethercote
nnethercote marked this pull request as ready for review October 8, 2026 20:17
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 8, 2026
@rust-bors

rust-bors Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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

This branch has not been deployed

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

4 participants