69 lines
2.6 KiB
Markdown
69 lines
2.6 KiB
Markdown
|
|
# Phase 85: Free Path Commit-Once (LEGACY-only) — Results
|
|||
|
|
|
|||
|
|
## Goal
|
|||
|
|
|
|||
|
|
`free_tiny_fast()` の free path で、**LEGACY に戻るまでの「儀式」(mono/policy/route 計算)**を、
|
|||
|
|
bench_profile 境界で commit-once して **hot path から除去**する。
|
|||
|
|
|
|||
|
|
- Scope: C4–C7 の **LEGACY route のみ**
|
|||
|
|
- Reversible: `HAKMEM_FREE_PATH_COMMIT_ONCE=0/1`
|
|||
|
|
- Safety: `HAKMEM_TINY_LARSON_FIX=1` なら fail-fast で commit 無効
|
|||
|
|
|
|||
|
|
## Implementation
|
|||
|
|
|
|||
|
|
- New box:
|
|||
|
|
- `core/box/free_path_commit_once_fixed_box.h`
|
|||
|
|
- `core/box/free_path_commit_once_fixed_box.c`
|
|||
|
|
- Integration:
|
|||
|
|
- `core/bench_profile.h` から `free_path_commit_once_refresh_from_env()` を呼ぶ
|
|||
|
|
- `core/front/malloc_tiny_fast.h` の `free_tiny_fast()` で Phase 9/10 より前に早期ハンドラ dispatch
|
|||
|
|
- Build:
|
|||
|
|
- `Makefile` に `core/box/free_path_commit_once_fixed_box.o` を追加
|
|||
|
|
|
|||
|
|
## A/B Results (SSOT, 10-run)
|
|||
|
|
|
|||
|
|
Control (`HAKMEM_FREE_PATH_COMMIT_ONCE=0`)
|
|||
|
|
- Mean: 52.75M ops/s
|
|||
|
|
- Median: 52.94M ops/s
|
|||
|
|
- Min: 51.70M ops/s
|
|||
|
|
- Max: 53.77M ops/s
|
|||
|
|
|
|||
|
|
Treatment (`HAKMEM_FREE_PATH_COMMIT_ONCE=1`)
|
|||
|
|
- Mean: 52.30M ops/s
|
|||
|
|
- Median: 52.42M ops/s
|
|||
|
|
- Min: 51.04M ops/s
|
|||
|
|
- Max: 53.03M ops/s
|
|||
|
|
|
|||
|
|
Delta: **-0.86% (NO-GO)**
|
|||
|
|
|
|||
|
|
## Diagnosis
|
|||
|
|
|
|||
|
|
### 1) Phase 10 (MONO LEGACY DIRECT) と最適化内容が被る
|
|||
|
|
|
|||
|
|
既に `free_tiny_fast_mono_legacy_direct_enabled()` が **C4–C7 の直行**(policy snapshot をスキップ)を提供しているため、
|
|||
|
|
Phase 85 が「追加で消せる儀式」が薄かった。
|
|||
|
|
|
|||
|
|
結果として、Phase 85 は **追加の gate/table 参照**を持ち込み、プラスになりにくい。
|
|||
|
|
|
|||
|
|
### 2) function pointer dispatch の税
|
|||
|
|
|
|||
|
|
Phase 85 は `entry->handler(base, class_idx, env)` の **間接呼び出し**を導入している。
|
|||
|
|
この種の間接分岐は branch predictor / layout の影響を受けやすく、SSOTでは net で負ける可能性がある。
|
|||
|
|
|
|||
|
|
### 3) layout tax の可能性
|
|||
|
|
|
|||
|
|
free hot path (`free_tiny_fast`) へ新規コードを挿入したことで text layout が揺れ、
|
|||
|
|
-0.x% の符号反転が起きやすい(既知パターン)。
|
|||
|
|
|
|||
|
|
## Decision
|
|||
|
|
|
|||
|
|
- **NO-GO**: `HAKMEM_FREE_PATH_COMMIT_ONCE` は **default OFF の research box**として保持
|
|||
|
|
- 物理削除はしない(layout tax の符号反転を避けるため)
|
|||
|
|
|
|||
|
|
## Follow-ups (if revisiting)
|
|||
|
|
|
|||
|
|
1. Handler cache をやめ、commit-once は **bitmask (legacy_mask) のみ**にする(間接 call 排除)。
|
|||
|
|
2. `env snapshot` を hot path で取る前に exit できる形を維持し、hot 側は **1本の早期return**に留める。
|
|||
|
|
3. “置換”は Phase 9/10 を compile-out できる条件が揃った後に Phase 86 で検討(同一バイナリ A/B を優先)。
|
|||
|
|
|