Conversation
Spans are translated once per statement, terminator, local, and item, and each call walked path components and hashed a `FileName` to dedup the file registration. Almost every hit lands on a handful of source files, so caching by rustc's `StableSourceFileId` lets us skip the work after the first miss per file. Measured on signalapp/SparsePostQuantumRatchet, hyperfine 10 runs: 6.355 s → 6.061 s (1.05× faster).
Many MIR statements share the same expansion span (especially within inlined or macro-generated code), and each call ran `lookup_char_pos` twice and re-resolved the source file. Caching `ty::Span -> SpanData` short-circuits that. Profile: `translate_span_from_smir` inclusive drops from 1.02% to 0.43%. Hyperfine (20 runs, SpQR): 5.919 s -> 5.885 s.
Contributor
|
nice |
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.
I got Claude to write performance improvements for Obol. It tried like 10 different things over 1h30 and only 2 of them make a vague improvement (5% total). It says the low-hanging fruits are really within Charon (and were already implemented in AeneasVerif/charon#1173.
It's not much, and I'm not sure we can do much better because, apparently, 55% of runtime is spent in const-eval.
Here's the summary written by Claude, I went through this and it doesn't sound banana and 5% is always good.
Summary
Two small caches in
translate_raw_spanthat together cut ~4.6% off translation time on a real-world workload.Spans are translated once per MIR statement, terminator, local, and item — so this is one of the hottest paths in the driver. Each call was
re-running path normalization,
FileNamehashing, andSourceMap::lookup_char_posfor spans we'd already seen.ddc49d4— cacheFileIdbySourceFilestable id.translate_filenamewalks path components and strips sysroot/cargo prefixes;register_filethen hashes aFileName. Caching on rustc'sStableSourceFileId(already 1:1 with the source file) skips all of that afterthe first hit per file. Falls through to
register_fileon miss, so dedup semantics are unchanged.a9bbacf— memoizetranslate_raw_spanbyty::Span. Many statements share the same expansion span (inlining, macros). Caching thefull
SpanDataskips both the file lookup and the twolookup_char_poscalls.Measurements
signalapp/SparsePostQuantumRatchet, hyperfine with--prepare 'touch src/lib.rs', 20 runs side-by-side:mainddc49d4a9bbacf(this branch)Profile confirms the mechanism:
translate_span_from_smirinclusive drops from 4.92% → 0.43% across the two commits.