Skip to content

Conversation

@AlexanderPortland
Copy link
Contributor

Profiling showed that codegen_span_stable was a significant bottleneck for Kani, as it has to do all the queries to rustc_public and logic to construct a Location for a given Span. However, I tested and found that the function was typically being called multiple (~500) times on the exact same Span throughout an execution.

This PR introduces a new cache to store the result of those calculations for future use.

Since the key to this cache is a rustc_public::Span, it's dependent on the type being Hash, something which will hopefully be implemented in rust-lang/rust#145018. For now, I've tested the change using a hacky transmute to implement Hash myself.

Results

Caching span codegen led to a nice 9.4% reduction in the end to end compilation of the standard library (@ commit 177d0fd, assuming #4276 lands).

Like #4276, this is a caching change and will have an associated memory overhead. Based on the max capacity of the map during execution, I estimate its peak size to be ~4.4MB when run on the standard library, which is around 0.13%-0.17% of Kani's total memory usage on the same run. This seems acceptable for the measured performance benefit.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

(using transmute hack to hash them)
(for when `rustc_public::Span` hopefully becomes `Hash`)
@AlexanderPortland AlexanderPortland requested a review from a team as a code owner August 6, 2025 21:33
@github-actions github-actions bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Aug 6, 2025
@AlexanderPortland AlexanderPortland marked this pull request as draft August 6, 2025 23:26
@AlexanderPortland
Copy link
Contributor Author

This change is superseded by #4313, which caches Span codegen in a more systematic way while also caching other kinds of codegen.

@AlexanderPortland AlexanderPortland deleted the cache-span-codegen branch August 26, 2025 00:59
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.

1 participant