Share body cache between harnesses within a codegen unit#4276
Merged
tautschnig merged 3 commits intomodel-checking:mainfrom Aug 20, 2025
Merged
Share body cache between harnesses within a codegen unit#4276tautschnig merged 3 commits intomodel-checking:mainfrom
tautschnig merged 3 commits intomodel-checking:mainfrom
Conversation
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.
Improves on #4259 by fully sharing the body cache between harnesses in the same codegen unit.
This cache initially only stored bodies which had been modified by our transformations, with the goal being to avoid doing those transformations multiple times. It does this job well, having a hit rate of ~66% on queries for modified bodies1.
However, I observed that even just querying to get the initial
Bodyfor a givenInstancewas a bottleneck, even if no passes needed to be applied. And, in this regard, the cache is much less effective, having a hit rate of only 1.8% if you count non-modified bodies1.Thus, this PR also adds all bodies to the cache, even those which were not modified by our passes.
Results
This change causes a further 7.7% reduction in the end to end compile time of the standard library (@ commit 177d0fd). The body cache has an average hit rate of 95.3% on that workload and, on a hit, we (at most) have to do an inexpensive clone from the cache rather than querying
rustc_public.As a caching solution, this comes with some memory overhead. Since we're sharing a cache and caching more bodies, the peak size of this cache has gone from 0.88 MB to 3.75 MB. This may seem like a significant increase (and I'm definitely open to feedback on whether it's acceptable), but given the fact that Kani hovered around 2.5-3.5 GB of RAM for that same run, this bigger cache would make up just 0.11%-0.15% of our total memory use.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
Footnotes
when verifying the standard library (@ commit 177d0fd) ↩ ↩2