# Phase 23: Per-op Default-OFF Tax Prune (compile-out write-once + unified-cache measurement) **Status**: ⚪ NEUTRAL(compile gate は維持、リンク除外はしない) ## Problem statement 過去の Phase 22(Research Box Prune)で確認したパターンの再適用: - 研究用の機能が **default OFF** なのに、 - hot path が毎回 `if (enabled())` / TLS read / small branch を払ってしまう 特に alloc/free が十分に速くなった後は、この種の **固定税(per-op tax)** が残りやすい。 ## Goal default OFF の knobs を **compile-out** できるようにし、hot/cold の固定税をゼロに寄せる。 - ✅ compile-out: `#if HAKMEM_*_COMPILED`(Phase 22 の勝ち筋) - ❌ link-out: Makefile から `.o` を抜く(Phase 22-2 の NO-GO) ## Scope (v1) ### A) Phase 5 E5-2: Header Write-Once Compile gate: - `HAKMEM_TINY_HEADER_WRITE_ONCE_COMPILED=0/1`(default: 0) 効果: - `HAKMEM_TINY_HEADER_WRITE_ONCE` が default OFF のままでも、 `tiny_header_finalize_alloc()` が毎回 ENV gate を評価する固定税を除去できる。 対象: - `core/box/tiny_header_box.h`: `tiny_header_finalize_alloc()` - `core/front/tiny_unified_cache.c`: `unified_cache_prefill_headers()` ### B) Unified Cache measurement (ENV-gated instrumentation) Compile gate: - `HAKMEM_TINY_UNIFIED_CACHE_MEASURE_COMPILED=0/1`(default: 0) 効果: - hot path の `unified_cache_measure_check()` 呼び出しと、 refill 側の測定コードを compile-out できる。 対象: - `core/front/tiny_unified_cache.h`: hit-path の measurement update(既に `#if` でガード) - `core/front/tiny_unified_cache.c`: refill-side measurement ## Box Theory framing - BuildFlagsBox(`core/hakmem_build_flags.h`)で compile-time 境界を作る。 - Rollback は build flag のみ(runtime ではなく build-time の“戻せる”)。 - Link set は固定(`.o` を外さない)。 ## A/B plan (build-level) 原則:**同じコードで、compile gate だけを切り替える**。 1) baseline(default, compile-out) - `make clean && make -j bench_random_mixed_hakmem` - `scripts/run_mixed_10_cleanenv.sh` 2) compiled-in(研究用) - `make clean && make -j EXTRA_CFLAGS='-DHAKMEM_TINY_HEADER_WRITE_ONCE_COMPILED=1 -DHAKMEM_TINY_UNIFIED_CACHE_MEASURE_COMPILED=1' bench_random_mixed_hakmem` - `scripts/run_mixed_10_cleanenv.sh` ## GO/NO-GO この種の “prune” は layout 変化が絡むため、判断は保守的に運用する: - GO: +0.5% 以上 - NEUTRAL: ±0.5% - NO-GO: -0.5% 以下(revert 推奨)