Skip to content

Share body cache between harnesses within a codegen unit#4276

Merged
tautschnig merged 3 commits intomodel-checking:mainfrom
AlexanderPortland:better-body-cache
Aug 20, 2025
Merged

Share body cache between harnesses within a codegen unit#4276
tautschnig merged 3 commits intomodel-checking:mainfrom
AlexanderPortland:better-body-cache

Conversation

@AlexanderPortland
Copy link
Contributor

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 Body for a given Instance was 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

  1. when verifying the standard library (@ commit 177d0fd) 2

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

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants