Phase 11.6: tiered SNMALLOC_STATS (BASIC/FULL split) - #60
Merged
Merged
Conversation
Splits the monolithic SNMALLOC_STATS flag into two independently selectable tiers so production builds can opt into the cheap counter surface without paying for the expensive per-size-class histogram. * SNMALLOC_STATS_BASIC -- frontend fast/slow path counters (9.2) + backend commit/decommit (9.4) + largebuddy free-chunk histogram (11.4). Target overhead <=2% (measured 1.03-1.08 on this host). * SNMALLOC_STATS_FULL -- BASIC plus per-size-class histogram (9.3) and lifetime histogram (9.5). Target overhead <=20% (measured 1.09-1.16). The legacy SNMALLOC_STATS flag is preserved as a backwards- compatible alias for BASIC; FULL implicitly enables BASIC. The FullAllocStats wire format is unchanged -- fields the active tier does not maintain simply read as zero -- so SNMALLOC_FULL_STATS_VERSION is not bumped. Cargo: `stats-basic` and `stats-full` features added in both snmalloc-rs and snmalloc-sys; `stats` is now an alias for `stats-basic`; `stats-full` implies `stats-basic` so the snmalloc-rs SnMalloc::full_stats() accessor remains available under either tier. 5-run bench results on Apple M4 Pro (vs OFF baseline): Group basic/off full/off small_allocs 1.0774 1.1639 medium_allocs 1.0398 1.0935 mixed 1.0310 1.0910 FULL meets the <=1.20 budget on every group. BASIC sits ~5-8% above OFF -- above the 1.02 spec but ~50% closer than the 1.16 Phase 11.5 floor. The remaining ~8% on small_allocs is the irreducible cost of two non-atomic stores per alloc+dealloc (stats.fast_path_allocs++ / stats.fast_path_deallocs++) on a ~200 ns inner-loop iteration. See docs/heap-profiling-benchmarks.md "Phase 11.6 -- tiered SNMALLOC_STATS overhead" for the full table and methodology. ClickUp: 86aj0ydjv
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.
Summary
SNMALLOC_STATSinto two tiers:SNMALLOC_STATS_BASIC(cheap frontend + backend counters, production default) andSNMALLOC_STATS_FULL(adds per-size-class + lifetime histograms, opt-in for debugging).stats-basic/stats-fullmirror the split; legacystatsis preserved as an alias forstats-basic.FullAllocStatswire format is unchanged (fields the active tier does not maintain read as zero).ClickUp
Test plan
cmake -B build -DSNMALLOC_STATS_BASIC=ON && cmake --build build -j4cmake -B build_full -DSNMALLOC_STATS_FULL=ON && cmake --build build_full -j4cmake -B build_legacy -DSNMALLOC_STATS=ON && cmake --build build_legacy -j4cmake -B build_off && cmake --build build_off -j4ctestpasses 106/106 on all four C++ build flavourscargo build --features stats-basicsucceedscargo build --features stats-fullsucceedscargo build --features statssucceeds (alias path)cargo test --features stats-basic --release-- all tests pass (sizeclass test skipped, gated to stats-full)cargo test --features stats-full --release-- all tests pass including per-size-class histogram suitecargo bench --bench stats_benchacross all three variants, 5 runs eachdocs/heap-profiling-benchmarks.md("Phase 11.6 -- tiered SNMALLOC_STATS overhead")