Skip to content

Four new-solver speedups - #160605

Draft
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:four-new-solver-speedups
Draft

Four new-solver speedups#160605
nnethercote wants to merge 4 commits into
rust-lang:mainfrom
nnethercote:four-new-solver-speedups

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Details in individual commits.

In `from_assoc`, we effectively create a sub-slice of `args`, via
interning. But in the case where the sub-slice has the same length as
the full slice, we can just reuse the slice. This gives a small perf
win.
`impl_is_default` is moderately expensive. This commit moves the cheaper
`consider_impl_candidate` check (which does `args_may_unify`) ahead, for
a small perf win. (Note: this change makes the new solver match what the
old solver does in `assemble_candidates_from_impls`.)
`consider_impl_candidate` calls it once and stores the result in
`goal_trait_ref`, and then calls it again shortly after. We can just use
`goal_trait_ref` for the second call. This is a moderate perf win.
It's expensive and is called unconditionally in
`NormalizesTo::consider_impl_candidate`, which is always called within a
loop. The result is invariant across the loop, so this commit hoists the
call outside of `consider_impl_candidate` and passes the return value in.

Notes:

- At the hoist sites, the expression is `goal.predicate.trait_ref(cx)`;
  for `NormalizesTo` this dispatches to
  `goal.predicate.alias.trait_ref(cx)`.

- Two other `GoalKind` methods are affected, but this doesn't
  change perf because they can get the `goal_trait_ref` cheaply.
@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 6, 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 6, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 6, 2026
@rust-bors

rust-bors Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: e30e628 (e30e6289716880a4180863db3ed4d7a9a67b7fd6)
Base parent: f73951d (f73951df0a5566d94d13b7954acd9f4ab1fa3734)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e30e628): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.9% [-21.5%, -0.3%] 16
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -1.4%)

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

mean range count
Regressions ❌
(primary)
1.5% [0.8%, 2.2%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-7.3% [-7.3%, -7.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.4% [-7.3%, 2.2%] 3

Cycles

Results (primary -3.8%, secondary -5.7%)

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)
5.2% [5.2%, 5.2%] 1
Improvements ✅
(primary)
-3.8% [-3.8%, -3.8%] 1
Improvements ✅
(secondary)
-7.5% [-12.7%, -4.3%] 6
All ❌✅ (primary) -3.8% [-3.8%, -3.8%] 1

Binary size

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

Bootstrap: 460.81s -> 458.926s (-0.41%)
Artifact size: 398.76 MiB -> 398.65 MiB (-0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 6, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

From the CI perf results, big wins on instruction counts for bitmaps and typenum, smaller wins on cycles.

From my local runs which include additional benchmarks, also a big win on hybrid-array:

image

@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: I used an LLM to analyze Cachegrind profiles and identify good optimization opportunities. I wrote all the code and text myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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