feat(profile): cache resolved symbols across symbolize() calls (CU-86aj3uw04) - #79
Merged
Conversation
Process-global, lazily-initialised `HashMap<usize, ResolvedFrame>` guarded by `OnceLock<Arc<Mutex<...>>>` memoizes `resolve_one`. First `HeapProfile::symbolize` pays the backtrace/gimli parse cost; later calls are a cache lookup per unique frame address. Motivation (CU-86aj3uw04): heap-profile-eval against :konfig_bin_heapprof showed ~17 MB transient Vec + ~20 ms self-CPU per /debug/heap-profile.pprof scrape, rooted at `backtrace::symbolize::gimli::macho::Object::parse`. Code addresses are stable for a process lifetime, so the answer is too. Surface: pub fn clear_symbol_cache(); // flush, keep cell Tests: symbol_cache_cell_stable_across_pprof_writes Arc-ptr equality symbol_cache_returns_equal_frame_on_second_call value equality
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.
What
Memoize
resolve_one(addr)behind a process-globalOnceLock<Arc<Mutex<HashMap<usize, ResolvedFrame>>>>.HeapProfile::symbolizenow hits the cache instead of re-runningbacktrace::resolveon every call. Newclear_symbol_cache()flushes contents without dropping the cell.Why
Heap-profile-eval against
:konfig_bin_heapprof(CU-86aj360ae, 2026-06-16) measured ~17 MB transient Vec + ~20 ms self-CPU per/debug/heap-profile.pprofscrape, rooted atbacktrace::symbolize::gimli::macho::Object::parse → Vec::reserve → __rust_realloc. Code addresses are stable within a process — first scrape pays parse cost, subsequent scrapes are free.CU-86aj35zev confirmed cost is intrinsic to the snmalloc-rs symbolicate path, not a downstream transitive.
Cost
Mutexlock +HashMaplookup per unique frame.Evidence
cargo test --features profiling,symbolicate --lib→ 42/42 pass.cargo build --features profiling(no symbolicate) → clean.symbol_cache_cell_stable_across_pprof_writes: Arc-ptr equality across twowrite_pprof_gzcalls + afterclear_symbol_cache.symbol_cache_returns_equal_frame_on_second_call: cached lookup matches fresh resolve.symbolize_resolves_known_function_namestill green.