Reduce next-solver memory usage by interning CanonicalQueryInput - #162031
Conversation
|
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. |
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Reduce next-solver memory usage by interning CanonicalQueryInput
This comment has been minimized.
This comment has been minimized.
|
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 @bors rollup=never rustc-perf Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
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.
CyclesResults (primary -1.9%, secondary 10.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 477.635s -> 478.315s (0.14%) |
| } | ||
| } | ||
|
|
||
| impl<'tcx> QueryKey for (crate::traits::solve::CanonicalInput<'tcx>, usize) { |
There was a problem hiding this comment.
that means you can remove the existing QueryKey for (CanonicalQueryInput<'tcx, T>, bool) impls? 🤔
There was a problem hiding this comment.
No, they're generic over T, while the newly added ones are not. Removing them causes many errors.
There was a problem hiding this comment.
what other query takes a tuple involving bool/usize? I do expect that we need the non-tuple one, but the other 2 surprise me
|
I'm not so sure anymore. I've been considering more and i think the fact NestedGoals stores a reference now is a drawback over, for example, storing CanonicalInputs in a Vec and handing out indices, kinda like you mentioned in the zulip at some point. To me it seems likely that's the direction where other improvements can be made. |
|
This PR feels small enough for us to easily revert this as part of a PR using indices, and using indices likely takes more than a few days, so preventing people compiling bevy from getting an OOM is probably worth it anyways |
|
@lcnr i resolved your reviews, what should we do about the perf regressions? |
|
|
||
| pub type CanonicalInput<I, T = <I as Interner>::Predicate> = | ||
| ty::CanonicalQueryInput<I, QueryInput<I, T>>; | ||
| pub type CanonicalInputData<I> = |
There was a problem hiding this comment.
oh wait, CanonicalInputData is not a wrapper type, it's just the name of a type alias?
🤔 want to instead do what we do for I::Probe which is just a &'tcx inspect::Probe? don't think we necessarily need a new type here
There was a problem hiding this comment.
It was a type alias before this whole PR too, then i made a wrapper around the type alias, then you reviewed asking if the wrapper needed to exist, i noticed it didn't, and removed it. kept the new name to not be ambiguous in other places, tho.
|
I do think we should be able to remove some @bors r+ rollup=never |
|
@bors rollup=iffy |
Rollup merge of #162031 - laundmo:opt-next-solver-memory, r=lcnr Reduce next-solver memory usage by interning CanonicalQueryInput 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
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (cd59165): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -1.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: missing data |
View all comments
Goal: Reduce memory usage of next-solver especially when exceeding recursion limit
Changes:
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