perf(core): reduce allocations and memory in ProfileAnalyzer#18
Merged
Conversation
…rofileAnalyzer Replace two pre-allocated Vec<u32> (stalls_in_bucket, factory_failure_counts) with a single Vec<u8> using HAD_STALL/HAD_FAILURE flag bits. Bottleneck classification only checks presence, never actual counts, so the bitfield is semantically identical with 75% less memory per bucket. Merge GateServed match arm to count magic states before stall check. Add unit tests for cumulative_magic_states() and cumulative_infidelity() helper methods.
Merging this PR will improve performance by 12.68%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | analyze[10] |
13.8 µs | 12 µs | +14.78% |
| ⚡ | analyze[500] |
314.1 µs | 280.9 µs | +11.82% |
| ⚡ | analyze[100] |
71.6 µs | 64.3 µs | +11.48% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/core-perf (766e3c7) with master (f3cd97b)
Lift HAD_STALL/HAD_FAILURE from function body to module-level constants, following standard Rust idiom for named flags.
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
Replace two per-bucket counter Vecs with a single Vec bitfield in ProfileAnalyzer::analyze, and add
unit tests for the cumulative helper methods on ExecutionProfile.
Why
Bottleneck classification only checks presence (> 0), never reads actual stall/failure counts. Tracking two
Vecs (8 bytes per bucket) for a boolean signal wastes memory and adds an unnecessary .zip() in the
post-loop pass. Per-stall detail is already preserved in stall_events, per-failure detail in the raw Trace.
How
by bucket_flags: Vec with HAD_STALL = 1 and HAD_FAILURE = 2 flag bits. 75% memory reduction per bucket.
Bottleneck classification iterates one Vec instead of zipping two.
unconditional work first, conditional second.
scaling, zero probability, and last-element-equals-total invariant.
Testing
Checklist