# ENV Variable Cleanup Analysis - Executive Summary ## Scope - **Initial sweep:** 221 unique ENV variables across the runtime (getenv()). - **Current view:** Core features Ultra/BG/HeapV2 are active and must be preserved (A/B gated only). - **Docs-only cleanup:** 21 documentation-only variables (zero getenv hits) are tracked separately in `SAFE_TO_DELETE_ENV_VARS.md`. ## Key Findings - **Active, keep**: Ultra path (`core/ultra/*`), BG spill (`hakmem_batch.c`, `hakmem_tiny_bg_spill.o`), HeapV2/FrontV2 (`core/front/tiny_heap_v2.h`, `tiny_alloc_fast.inc.h`) are compiled in and runtime-gated. Removing their ENV toggles would break A/B rollback. - **SFC is live**: `hakmem_tiny_sfc.o` is built; `HAKMEM_SFC_ENABLE/CAPACITY/REFILL_COUNT/DEBUG/STATS_DUMP/CASCADE_PCT` all drive behavior. Debug getenv duplication remains the top low-risk cleanup. - **Doc-only set**: 21 proposal-only ENV names (adaptive presets, generic debug knobs, legacy build flags) have no getenv calls; safe to drop from docs with zero runtime impact. - **Count drift**: Including `.inc` helpers raises the current getenv surface to ~279 names; initial 221 figure is kept as the baseline for this project’s first pass. ## Quick Wins (low risk, Box-friendly) - **SFC_DEBUG dedup**: Move the four `HAKMEM_SFC_DEBUG` getenv calls behind one init-time flag (`hakmem_tiny_sfc.c` as the boundary). Reduces hot-path getenvs by 3. - **Doc hygiene**: Remove the 21 docs-only names from `docs/specs/ENV_VARS*.md` to keep the supported surface visible and reversible. ## Items to Keep as-is (cannot delete) - **Ultra toggles**: `HAKMEM_TINY_ULTRA_*`, `HAKMEM_ULTRA_SLIM_STATS` — gated experiments but compiled; keep for rollback. - **BG system**: `HAKMEM_BATCH_BG`, `HAKMEM_L25_BG_DRAIN`, `HAKMEM_L25_BG_MS` — enabled by default; removal would change behavior. - **HeapV2/FrontV2**: `HAKMEM_TINY_HEAP_V2_*`, `HAKMEM_TINY_FRONT_V2/SLIM/DIRECT/METRICS/DUMP` — active path for tiny frontend; keep. ## 最新アクション(このセッション) - `HAKMEM_SFC_DEBUG` を init 1回読みへ集約(ホットパス getenv を排除)。 - リリースビルドで以下の DEBUG/TRACE/STATS 系 ENV を無効化(getenv しない): - `HAKMEM_TINY_TRACE_RING`, `HAKMEM_TINY_DUMP_RING_ATEXIT` - `HAKMEM_TINY_RF_TRACE`, `HAKMEM_TINY_MAILBOX_TRACE`, `HAKMEM_TINY_MAILBOX_TRACE_LIMIT`, `HAKMEM_TINY_MAILBOX_SLOWDISC(_PERIOD)` - `HAKMEM_SS_PREWARM_DEBUG`, `HAKMEM_SS_FREE_DEBUG` - `HAKMEM_TINY_FRONT_METRICS`, `HAKMEM_TINY_FRONT_DUMP` - `HAKMEM_TINY_COUNTERS_DUMP`, `HAKMEM_TINY_REFILL_DUMP` - `HAKMEM_PTR_TRACE_DUMP`, `HAKMEM_PTR_TRACE_VERBOSE` ## Next Steps 1) 残る DEBUG/TRACE/STATS 系 ENV を同様にリリースビルドで無効化 or init 1回読みへ移動。 2) 21個のドキュメント専用変数を `docs/specs/ENV_VARS*.md` から削除。 3) Ultra/BG/HeapV2 は現役のため A/B ゲートを維持したまま、削除は別フェーズで判断。 See `ENV_CLEANUP_PLAN.md` for the full getenv map (file+line) and `ENV_CONSOLIDATION_PLAN.md` for the long-term policy reduction (149 → ~30).