Perf: Only scan the affected suffix of the provisional cache - #161130
Open
Dandandan wants to merge 1 commit into
Open
Perf: Only scan the affected suffix of the provisional cache#161130Dandandan wants to merge 1 commit into
Dandandan wants to merge 1 commit into
Conversation
`insert_provisional` walks the whole provisional cache on every insert to
lower `reached_depth`. Everything it can affect was inserted while
`from_dfn` was on the stack, so it is a suffix of this insertion-ordered
map and the walk can stop at the first older entry.
The full walk is quadratic in the size of the cache, which only fills up
for mutually recursive types. Proving `Send` for a graph of N such types
did about N^2 iterations of this loop -- 641M of them for N=480.
`evaluate_obligation` on that graph:
N=60 104ms -> 61ms
N=120 315ms -> 118ms
N=240 886ms -> 243ms
N=480 3.06s -> 0.55s
That is the linear growth the same graph already has when it is acyclic.
Dandandan
marked this pull request as ready for review
August 15, 2026 09:47
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @nnethercote (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
insert_provisionalwalks the whole provisional cache on every insert, to lowerreached_depthon entries at or abovefrom_dfn. Everything it can affect wasinserted while
from_dfnwas on the stack, so those entries are a suffix of thisinsertion-ordered map, and the walk can stop at the first older entry.
The full walk is quadratic in the size of the cache. That cache only fills up for
mutually recursive types, so this shows up when proving
SendorSyncfor agraph of such types: for a graph of N of them the loop ran about N² times.
evaluate_obligationself time on that graph:Growth goes from superlinear to linear, which is what the same graph already does
when it has no cycles.
I ran into this looking at DataFusion, whose
ExprandLogicalPlantypes aremutually recursive across a few hundred types.
AI Disclosure
I used LLM (Claude) to run some experiments and change the code