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

Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@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

Copy link
Copy Markdown
Collaborator

Queued 9d1834c with parent 5321a4f, future comparison URL.
There are currently 0 preceding artifacts in the queue.
It will probably take at least ~1.0 hours until the benchmark run finishes.

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

Labels

S-waiting-on-perf Status: Waiting on a perf run to be completed. 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