Avoid redundant next-solver fulfillment scans - #161348
Conversation
|
@nnethercote I avoided some of the redundant fulfillment checks where there was no change in the inference state |
|
I'm not expert enough with the trait solver to evaluate this. (@lcnr or @jdonszelmann might have opinions.) It does look like a fairly complex change without much explanation. Did you write the code yourself? |
I used the stalled goal fast path from #158249 and the try_evaluate_obligations work in #160479 |
|
this seems vaguely appropriate, the core idea "fast path if literally no infer var changed since last run" makes a lot of sense to me. The way it's written right now feels very brittle and I would like to encapsulate this somehow in a way that makes it harder to accidentally forget to check/update something. I considered separately having a shared list of what every goal in the fulfillment context is stalled on, so we dont need to iterate over it if literally nothing in it changed even if unrelated infer vars changed. Why do you not reset this counter when rolling back a snapshot. There's a lot of open design space here, think this is definitely a good direction :> |
|
One option is to store the "state after last fulfillment loop" in the That way you could also track "highest mentioned infer var indices" and "lowest constrained infer var" to ignore any constraints for infer vars which the fulfillment context is not stalled on. Idk if that matters :> |
|
@lcnr Thanks for your review I agree about the brittleness though |
but why? rolling them back should be completely correct, should it not? |
I am still unsure about this part but I think you are right here |
aec0740 to
20985b8
Compare
|
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
@rustbot ready |
|
@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.
Avoid redundant next-solver fulfillment scans
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (5d793fd): 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.5%, secondary -0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 3.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 456.256s -> 463.808s (1.66%) |
Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
20985b8 to
3761377
Compare
|
@lcnr do you think the InferCtxt state + mem::swap approach would be cleaner than keeping revisions in TypeVariableStorage ? 🤔 |
Refs #159933
The regression comes from repeatedly traversing the pending fulfillment queue even when the inference state the pending goals are stalled on has not changed. it introduces a fast path which records the relevant inference revisions and aggregate stalled state. a subsequent fulfillment invocation can skip traversing the pending queue when that state is unchanged and all pending goals can be tracked, otherwise we fall back to the regular fulfillment loop
the type-variable revisions are snapshot-aware. revision changes use the existing inference undo log and rolling back a probe restores the revisions together with the corresponding inference state
On the reproducer from the issue: