## Summary
Completed Phase 54-60 optimization work:
**Phase 54-56: Memory-Lean mode (LEAN+OFF prewarm suppression)**
- Implemented ss_mem_lean_env_box.h with ENV gates
- Balanced mode (LEAN+OFF) promoted as production default
- Result: +1.2% throughput, better stability, zero syscall overhead
- Added to bench_profile.h: MIXED_TINYV3_C7_BALANCED preset
**Phase 57: 60-min soak finalization**
- Balanced mode: 60-min soak, RSS drift 0%, CV 5.38%
- Speed-first mode: 60-min soak, RSS drift 0%, CV 1.58%
- Syscall budget: 1.25e-7/op (800× under target)
- Status: PRODUCTION-READY
**Phase 59: 50% recovery baseline rebase**
- hakmem FAST (Balanced): 59.184M ops/s, CV 1.31%
- mimalloc: 120.466M ops/s, CV 3.50%
- Ratio: 49.13% (M1 ACHIEVED within statistical noise)
- Superior stability: 2.68× better CV than mimalloc
**Phase 60: Alloc pass-down SSOT (NO-GO)**
- Implemented alloc_passdown_ssot_env_box.h
- Modified malloc_tiny_fast.h for SSOT pattern
- Result: -0.46% (NO-GO)
- Key lesson: SSOT not applicable where early-exit already optimized
## Key Metrics
- Performance: 49.13% of mimalloc (M1 effectively achieved)
- Stability: CV 1.31% (superior to mimalloc 3.50%)
- Syscall budget: 1.25e-7/op (excellent)
- RSS: 33MB stable, 0% drift over 60 minutes
## Files Added/Modified
New boxes:
- core/box/ss_mem_lean_env_box.h
- core/box/ss_release_policy_box.{h,c}
- core/box/alloc_passdown_ssot_env_box.h
Scripts:
- scripts/soak_mixed_single_process.sh
- scripts/analyze_epoch_tail_csv.py
- scripts/soak_mixed_rss.sh
- scripts/calculate_percentiles.py
- scripts/analyze_soak.py
Documentation: Phase 40-60 analysis documents
## Design Decisions
1. Profile separation (core/bench_profile.h):
- MIXED_TINYV3_C7_SAFE: Speed-first (no LEAN)
- MIXED_TINYV3_C7_BALANCED: Balanced mode (LEAN+OFF)
2. Box Theory compliance:
- All ENV gates reversible (HAKMEM_SS_MEM_LEAN, HAKMEM_ALLOC_PASSDOWN_SSOT)
- Single conversion points maintained
- No physical deletions (compile-out only)
3. Lessons learned:
- SSOT effective only where redundancy exists (Phase 60 showed limits)
- Branch prediction extremely effective (~0 cycles for well-predicted branches)
- Early-exit pattern valuable even when seemingly redundant
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2.7 KiB
2.7 KiB
Phase 43 — Header write tax reduction(alloc hot: preserve-class skip)
目的
FAST build(make perf_fast)で、tiny_region_id_write_header(alloc hot)の 実作業を減らして +1% 以上を狙う。
Phase 42 の結論: gate はもう Top 50 圏外。次は「実作業(header store)」が芯。
背景(観測)
tiny_region_id_write_headerが runtime profiling で大きい(alloc の固定作業)。- Tiny の nextptr 仕様では C1–C6 は header を保持(next_off=1)、C0/C7 は header を上書き(next_off=0)。
core/tiny_nextptr.h(SSOT)core/box/tiny_header_box.hのtiny_class_preserves_header()
つまり **C1–C6 については “free 中に header が壊れない”**前提が成立するので、alloc で毎回 header を書く必要が本来ない。
方針(Box Theory)
- Standard/OBSERVE は触らない(安全・互換を維持)。
- FAST(
HAKMEM_BENCH_MINIMAL=1)の中だけで、alloc 側の header write を減らす。 - link-out / 物理削除は禁止(layout tax の前例がある)。
Step 0: Invariant 確認(必須)
- nextptr 仕様確認
- C0: next_off=0(header 上書き)
- C1–C6: next_off=1(header 保持)
- C7: next_off=0(デフォルト)
- 「header 保持クラス」の block が最初に header を持つこと
- linear carve / refill 経路で、C1–C6 には header が書かれていることを確認する。
- 例:
core/tiny_refill_opt.hの carve/popfreenode でtiny_header_write_if_preserved()が走ること
- 例:
Step 1: 変更(FAST 限定)
ターゲット:
core/tiny_region_id.hのtiny_region_id_write_header(...)の hot 経路
変更方針:
tiny_class_preserves_header(class_idx)==trueのクラス(C1–C6)について、- FAST では alloc 時の header store をスキップ
user = header_ptr + 1を返すだけ(header は “既に正しい”前提)
tiny_class_preserves_header(class_idx)==false(C0/C7)だけは 従来どおり header を書く
重要:
- 既存の Phase 21 “HOTFULL” の hot/cold split を壊さない(FAST でも HOTFULL の直線性を維持)。
Step 2: A/B(FAST 10-run)
baseline:
make perf_fast(FAST v3)
treatment:
make perf_fast(FAST v4 / Phase 43)
判定(risk 高めなので閾値を上げる):
- GO: +1.0% 以上
- NEUTRAL: ±1.0%
- NO-GO: -1.0% 以下(即 revert)
Step 3: 健康診断(最小)
make perf_observeを 1回(crash/ASSERT がないこと)
ログ
docs/analysis/PHASE43_HEADER_WRITE_TAX_REDUCTION_RESULTS.mdを作成し、10-run mean/median と判定を書く。docs/analysis/PERFORMANCE_TARGETS_SCORECARD.mdの FAST build 履歴を更新。