Files
hakmem/docs/analysis/PHASE15_UNIFIEDCACHE_LIFO_1_NEXT_INSTRUCTIONS.md
Moe Charm (CI) 87fa27518c Phase 15 v1: UnifiedCache FIFO→LIFO NEUTRAL (-0.70% Mixed, +0.42% C7)
Transform existing array-based UnifiedCache from FIFO ring to LIFO stack.

A/B Results:
- Mixed (16-1024B): -0.70% (52,965,966 → 52,593,948 ops/s)
- C7-only (1025-2048B): +0.42% (78,010,783 → 78,335,509 ops/s)

Verdict: NEUTRAL (both below +1.0% GO threshold) - freeze as research box

Implementation:
- L0 ENV gate: tiny_unified_lifo_env_box.{h,c} (HAKMEM_TINY_UNIFIED_LIFO=0/1)
- L1 LIFO ops: tiny_unified_lifo_box.h (unified_cache_try_pop/push_lifo)
- L2 integration: tiny_front_hot_box.h (mode check at entry)
- Reuses existing slots[] array (no intrusive pointers)

Root Causes:
1. Mode check overhead (tiny_unified_lifo_enabled() call)
2. Minimal LIFO vs FIFO locality delta in practice
3. Existing FIFO ring already well-optimized

Bonus Fix: LTO bug for tiny_c7_preserve_header_enabled() (Phase 13/14 latent issue)
- Converted static inline to extern + non-inline implementation
- Fixes undefined reference during LTO linking

Design: docs/analysis/PHASE15_UNIFIEDCACHE_LIFO_1_DESIGN.md
Results: docs/analysis/PHASE15_UNIFIEDCACHE_LIFO_1_AB_TEST_RESULTS.md

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-15 02:19:26 +09:00

2.4 KiB
Raw Blame History

Phase 15: UnifiedCache FIFO→LIFO (Stack) v1 — Next Instructions

設計: docs/analysis/PHASE15_UNIFIEDCACHE_LIFO_1_DESIGN.md


0. Status / Why now

  • Phase 14 v1/v2intrusive tcacheNEUTRAL → freezedefault OFF
  • 次の狙いは intrusive を増やさず、既存 slots[] を使って FIFO ring → LIFO stack に変える(形状で命令数と局所性を取りに行く)

1. GO 条件

Mixed 10-runclean env:

  • GO: mean +1.0% 以上
  • NO-GO: mean -1.0% 以下
  • NEUTRAL: ±1.0% → research box freeze

2. Patch 順(小さく積む)

Patch 1: L0 ENV gate box戻せる

新規:

  • core/box/tiny_unified_lifo_env_box.{h,c}

ENV:

  • HAKMEM_TINY_UNIFIED_LIFO=0/1default 0

要件:

  • hot path に getenv() を置かないcached
  • bench_profile の putenv() 同期が必要なら refresh API を用意(ただし mode 切替の整合に注意)

Patch 2: L1 LIFO 操作箱(副作用ゼロ)

新規static inline 想定):

  • core/box/tiny_unified_lifo_box.h

API:

  • unified_cache_try_pop_lifo(int class_idx) -> void* base_or_null
  • unified_cache_try_push_lifo(int class_idx, void* base) -> int handled(1/0)

実装方針:

  • TinyUnifiedCachetail を “top” とみなす(互換優先)
  • LIFO enabled のときは head は使わない(または 0 に固定)

Patch 3: 統合点(入口で 1 回だけ)

統合候補(優先順):

  1. core/box/tiny_front_hot_box.hhot alloc/free の実体)
  2. core/front/tiny_unified_cache.h(広範囲に効かせたい場合)

原則:

  • “mode 判定” は 関数入口で 1 回だけ
  • hot パス中で mode の再判定を散らさないPhase 11 の反省)

Patch 4: 可視化(最小)

必要なときだけ:

  • LIFO hit/miss を TLS カウンタatomic 禁止)
  • ワンショット dumpENV opt-in

3. A/B同一バイナリ

Baseline:

HAKMEM_TINY_UNIFIED_LIFO=0 scripts/run_mixed_10_cleanenv.sh

Optimized:

HAKMEM_TINY_UNIFIED_LIFO=1 scripts/run_mixed_10_cleanenv.sh

追加(局所性が効くか):

HAKMEM_BENCH_C7_ONLY=1 HAKMEM_TINY_UNIFIED_LIFO=0 scripts/run_mixed_10_cleanenv.sh
HAKMEM_BENCH_C7_ONLY=1 HAKMEM_TINY_UNIFIED_LIFO=1 scripts/run_mixed_10_cleanenv.sh

4. 健康診断

scripts/verify_health_profiles.sh

5. Rollback

  • export HAKMEM_TINY_UNIFIED_LIFO=0