Skip to content

Reduce next-solver memory usage by interning CanonicalQueryInput - #162031

Open
laundmo wants to merge 2 commits into
rust-lang:mainfrom
laundmo:opt-next-solver-memory
Open

Reduce next-solver memory usage by interning CanonicalQueryInput#162031
laundmo wants to merge 2 commits into
rust-lang:mainfrom
laundmo:opt-next-solver-memory

Conversation

@laundmo

@laundmo laundmo commented Aug 30, 2026

Copy link
Copy Markdown

Goal: Reduce memory usage of next-solver especially when exceeding recursion limit

Changes:

  • Added Interner::CanonicalInput associated type and surrounding interning machinery (mostly copied from ExternalConstraints)
  • Changed Cx::Input to be I:CanonicalInput and adjusted other places in the code to match, including calling the interning during canonicalize_goal

Results:
According to Heaptrack (and btop) peak memory usage for compiling bevy_render (like #161748) with next-solver enabled was reduced from ~15GiB to ~4GiB since most of it was the HashMap index for NestedGoals (and search_graph::GlobalCache), which used to be 56 bytes (IIRC), but now is a single reference thanks to Interned.

Closes (maybe): #161748
Tracking issue: rust-lang/goals#113 and #160895 (comment)

r? @lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 30, 2026
@rustbot

rustbot commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @lcnr (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

@ShoyuVanilla

Copy link
Copy Markdown
Member

@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 31, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
Reduce next-solver memory usage by interning CanonicalQueryInput
@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 9d1834c (9d1834c69e38df691a50a3052833ce4cb83252c2)
Base parent: 5321a4f (5321a4f40c957cf3587c055e77461febc2ebc865)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9d1834c): 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.2% [0.1%, 0.2%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 3
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.1%, secondary 0.9%)

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

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
6.7% [4.0%, 10.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.5% [-2.3%, -0.7%] 7
All ❌✅ (primary) 1.1% [1.1%, 1.1%] 1

Cycles

Results (primary -1.9%, secondary 10.0%)

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)
10.0% [10.0%, 10.0%] 1
Improvements ✅
(primary)
-1.9% [-1.9%, -1.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.9% [-1.9%, -1.9%] 1

Binary size

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

Bootstrap: 477.635s -> 478.315s (0.14%)
Artifact size: 402.71 MiB -> 402.95 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 Aug 31, 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-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.

5 participants