Skip to content

Phase 11.6: tiered SNMALLOC_STATS (BASIC/FULL split) - #60

Merged
jayakasadev merged 1 commit into
mainfrom
feature/phase-11-6-tiered-stats
Jun 12, 2026
Merged

jayakasadev merged 1 commit into
mainfrom
feature/phase-11-6-tiered-stats

Conversation

@jayakasadev

Copy link
Copy Markdown
Owner

Summary

  • Splits monolithic SNMALLOC_STATS into two tiers: SNMALLOC_STATS_BASIC (cheap frontend + backend counters, production default) and SNMALLOC_STATS_FULL (adds per-size-class + lifetime histograms, opt-in for debugging).
  • Cargo features stats-basic / stats-full mirror the split; legacy stats is preserved as an alias for stats-basic. FullAllocStats wire format is unchanged (fields the active tier does not maintain read as zero).
  • 5-run bench (Apple M4 Pro, vs OFF): FULL ratios 1.09-1.16 (meets <=1.20 target on every group); BASIC ratios 1.03-1.08 (above 1.02 spec but ~50% closer than the 1.16 Phase 11.5 floor).

ClickUp

  • 86aj0ydjv

Test plan

  • cmake -B build -DSNMALLOC_STATS_BASIC=ON && cmake --build build -j4
  • cmake -B build_full -DSNMALLOC_STATS_FULL=ON && cmake --build build_full -j4
  • cmake -B build_legacy -DSNMALLOC_STATS=ON && cmake --build build_legacy -j4
  • cmake -B build_off && cmake --build build_off -j4
  • ctest passes 106/106 on all four C++ build flavours
  • cargo build --features stats-basic succeeds
  • cargo build --features stats-full succeeds
  • cargo build --features stats succeeds (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 suite
  • cargo bench --bench stats_bench across all three variants, 5 runs each
  • Acceptance table updated in docs/heap-profiling-benchmarks.md ("Phase 11.6 -- tiered SNMALLOC_STATS overhead")

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
@jayakasadev
jayakasadev merged commit b8476b7 into main Jun 12, 2026
22 of 211 checks passed
@jayakasadev
jayakasadev deleted the feature/phase-11-6-tiered-stats branch June 12, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant