Files
hakmem/docs/analysis/ENV_CLEANUP_SUMMARY.md
Moe Charm (CI) 43015725af ENV cleanup: Add RELEASE guards to DEBUG ENV variables (14 vars)
Added compile-time guards (#if HAKMEM_BUILD_RELEASE) to eliminate
DEBUG ENV variable overhead in RELEASE builds.

Variables guarded (14 total):
- 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
- 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

Files modified (9 core files):
- core/tiny_debug_ring.c (ring trace/dump)
- core/box/mailbox_box.c (mailbox trace + slowdisc)
- core/tiny_refill.h (refill trace)
- core/hakmem_tiny_superslab.c (superslab debug)
- core/box/ss_allocation_box.c (allocation debug)
- core/tiny_superslab_free.inc.h (free debug)
- core/box/front_metrics_box.c (frontend metrics)
- core/hakmem_tiny_stats.c (stats dump)
- core/ptr_trace.h (pointer trace)

Bug fixes during implementation:
1. mailbox_box.c - Fixed variable scope (moved 'used' outside guard)
2. hakmem_tiny_stats.c - Fixed incomplete declarations (on1, on2)

Impact:
- Binary size: -85KB total
  - bench_random_mixed_hakmem: 319K → 305K (-14K, -4.4%)
  - larson_hakmem: 380K → 309K (-71K, -18.7%)
- Performance: No regression (16.9-17.9M ops/s maintained)
- Functional: All tests pass (Random Mixed + Larson)
- Behavior: DEBUG ENV vars correctly ignored in RELEASE builds

Testing:
- Build: Clean compilation (warnings only, pre-existing)
- 100K Random Mixed: 16.9-17.9M ops/s (PASS)
- 10K Larson: 25.9M ops/s (PASS)
- DEBUG ENV verification: Correctly ignored (PASS)

Result: 14 DEBUG ENV variables now have zero overhead in RELEASE builds.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 03:41:07 +09:00

44 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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 projects 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).