Files
hakmem/docs/analysis/PERFORMANCE_TARGETS_SCORECARD.md
Moe Charm (CI) b7085c47e1 Phase 35-39: FAST build optimization complete (+7.13% cumulative)
Phase 35-A: BENCH_MINIMAL gate function elimination (GO +4.39%)
- tiny_front_v3_enabled() → constant true
- tiny_metadata_cache_enabled() → constant 0
- learner_v7_enabled() → constant false
- small_learner_v2_enabled() → constant false

Phase 36: Policy snapshot init-once (GO +0.71%)
- small_policy_v7_snapshot() version check skip in BENCH_MINIMAL
- TLS cache for policy snapshot

Phase 37: Standard TLS cache (NO-GO -0.07%)
- TLS cache for Standard build attempted
- Runtime gate overhead negates benefit

Phase 38: FAST/OBSERVE/Standard workflow established
- make perf_fast, make perf_observe targets
- Scorecard and documentation updates

Phase 39: Hot path gate constantization (GO +1.98%)
- front_gate_unified_enabled() → constant 1
- alloc_dualhot_enabled() → constant 0
- g_bench_fast_front, g_v3_enabled blocks → compile-out
- free_dispatch_stats_enabled() → constant false

Results:
- FAST v3: 56.04M ops/s (47.4% of mimalloc)
- Standard: 53.50M ops/s (45.3% of mimalloc)
- M1 target (50%): 5.5% remaining

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 15:01:56 +09:00

200 lines
7.7 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.

# Performance Targetsmimalloc 追跡の"数値目標"
目的: 速さだけでなく **syscall / メモリ安定性 / 長時間安定性**を含めて「勝ち筋」を固定する。
## 運用方針Phase 38 確定)
**比較基準は FAST build** を正とする:
- **FAST**: 純粋な性能計測gate function 定数化、診断カウンタ OFF
- **Standard**: 安全・互換の基準ENV gate 有効、本線リリース用)
- **OBSERVE**: 挙動観測・デバッグ(診断カウンタ ON
mimalloc との比較は **FAST build** で行うStandard は fixed tax を含むため公平でない)。
## Current snapshot2025-12-16, Phase 39
計測条件(再現の正):
- Mixed: `scripts/run_mixed_10_cleanenv.sh``ITERS=20000000 WS=400`
- 10-run mean/median
- Git: `HEAD` (Phase 39)
### hakmem Build Variants同一バイナリレイアウト
| Build | Mean (M ops/s) | Median (M ops/s) | vs mimalloc | 備考 |
|-------|----------------|------------------|-------------|------|
| **FAST v3** | 56.04 | - | **47.4%** | 性能評価の正 |
| Standard | 53.50 | - | 45.3% | 安全・互換基準 |
| OBSERVE | TBD | - | - | 診断カウンタ ON |
**FAST vs Standard delta: +4.8%**gate function overhead の差)
### Reference allocators別バイナリ、layout 差あり)
| allocator | mean (M ops/s) | median (M ops/s) | ratio vs mimalloc (mean) |
|----------|-----------------|------------------|--------------------------|
| libc (same binary) | 76.257 | 76.661 | 64.5% |
| system (separate) | 81.540 | 81.801 | 69.0% |
| mimalloc (separate)| 118.176| 118.497 | 100% |
Notes:
- `system/mimalloc` は別バイナリ計測のため **layouttext size/I-cache差分を含む reference**
- `libc (same binary)``HAKMEM_FORCE_LIBC_ALLOC=1` により、同一レイアウト上での比較の目安。
- **mimalloc 比較は FAST build を使用すること**Standard の gate overhead は hakmem 固有の税)
## 1) Speed相対目標
前提: **FAST build** で hakmem vs mimalloc を比較するStandard は gate overhead を含むため不公平)。
推奨マイルストーンMixed 161024B, FAST build
| Milestone | Target | Current (FAST v3) | Status |
|-----------|--------|-------------------|--------|
| M1 | mimalloc の **50%** | 47.4% | 🔴 未達 |
| M2 | mimalloc の **55%** | - | 🔴 未達 |
| M3 | mimalloc の **60%** | - | 🔴 未達 |
| M4 | mimalloc の **6570%** | - | 🔴 未達(構造改造必要)|
**現状:** FAST v3 = 56.04M ops/s = mimalloc の 47.4%M1 未達、あと +5.5% 必要)
## 2) Syscall budgetOS churn
Tiny hot path の理想:
- steady-statewarmup 後)で **mmap/munmap/madvise = 0**(または “ほぼ 0”
目安(許容):
- `mmap+munmap+madvise` 合計が **1e8 ops あたり 1 回以下**= 1e-8 / op
Current:
- `HAKMEM_SS_OS_STATS=1`Mixed, `iters=200000000 ws=400`:
- `[SS_OS_STATS] alloc=9 free=11 madvise=9 madvise_disabled=0 mmap_total=9 fallback_mmap=0 huge_alloc=0`
観測方法(どちらか):
- 内部: `HAKMEM_SS_OS_STATS=1``[SS_OS_STATS]`madvise/disabled 等)
- 外部: `perf stat` の syscall events か `strace -c`(短い実行で回数だけ見る)
## 3) Memory stabilityRSS / fragmentation
最低条件Mixed / ws 固定の soak
- RSS が **時間とともに単調増加しない**
- 1時間の soak で RSS drift が **+5% 以内**(目安)
Current:
- TBDsoak のテンプレは今後スクリプト化)
推奨指標:
- RSSpeak / steady
- page faults増え続けないこと
- allocator 内部の “inuse / committed” 比(取れるなら)
## 4) Long-run stability性能・一貫性
最低条件:
- 3060 分の soak で ops/s が **-5% 以上落ちない**
- CV変動係数**~12%** に収まる(現状の運用と整合)
Current:
- Mixed 10-run上の snapshot: CV ≈ 0.91%mean 54.646M / min 53.608M / max 55.311M
## 5) 判定ルール(運用)
- runtime 変更ENVのみ: GO 閾値 +1.0%Mixed 10-run mean
- build-level 変更compile-out 系): GO 閾値 +0.5%layout の揺れを考慮)
## 6) Build VariantsFAST / Standard / OBSERVE— Phase 38 運用
### 3種類のビルド
| Build | Binary | 目的 | 特徴 |
|-------|--------|------|------|
| **FAST** | `bench_random_mixed_hakmem_minimal` | 純粋な性能計測 | gate function 定数化、診断 OFF |
| **Standard** | `bench_random_mixed_hakmem` | 安全・互換基準 | ENV gate 有効、本線リリース用 |
| **OBSERVE** | `bench_random_mixed_hakmem_observe` | 挙動観測 | 診断カウンタ ON、perf 分析用 |
### 運用ルールPhase 38 確定)
1. **性能評価は FAST build で行う**mimalloc 比較の正)
2. **Standard は安全基準**gate overhead は許容、本線機能の互換性優先)
3. **OBSERVE はデバッグ用**(性能評価には使わない、診断出力あり)
### FAST build 履歴
| Version | Mean (ops/s) | Delta | 変更内容 |
|---------|--------------|-------|----------|
| FAST v1 | 54,557,938 | baseline | Phase 35-A: gate function 定数化 |
| FAST v2 | 54,943,734 | +0.71% | Phase 36: policy snapshot init-once |
| **FAST v3** | 56,040,000 | +1.98% | Phase 39: hot path gate 定数化 |
**FAST v3 で定数化されたもの:**
- `tiny_front_v3_enabled()` → 常に `true`
- `tiny_metadata_cache_enabled()` → 常に `0`
- `small_policy_v7_snapshot()` → version check スキップ、init-once TLS cache
- `learner_v7_enabled()` → 常に `false`
- `small_learner_v2_enabled()` → 常に `false`
- `front_gate_unified_enabled()` → 常に `1`Phase 39
- `alloc_dualhot_enabled()` → 常に `0`Phase 39
- `g_bench_fast_front` block → compile-outPhase 39
- `g_v3_enabled` block → compile-outPhase 39
- `free_dispatch_stats_enabled()` → 常に `false`Phase 39
### 使い方Phase 38 ワークフロー)
**推奨: 自動化ターゲットを使用**
```bash
# FAST 10-run 性能評価mimalloc 比較の正)
make perf_fast
# OBSERVE health checksyscall/診断確認)
make perf_observe
# 両方実行
make perf_all
```
**手動実行(個別制御が必要な場合)**
```bash
# FAST build のみビルド
make bench_random_mixed_hakmem_minimal
# Standard build のみビルド
make bench_random_mixed_hakmem
# OBSERVE build のみビルド
make bench_random_mixed_hakmem_observe
# 10-run 実行(任意の binary で)
scripts/run_mixed_10_cleanenv.sh
```
### Phase 37 教訓Standard 最適化の限界)
Standard build を速くする試みTLS cacheは NO-GO (-0.07%):
- Runtime gate (lazy-init) は必ず overhead を持つ
- Compile-time constant (BENCH_MINIMAL) が唯一の解
- **結論:** Standard は安全基準として維持、性能は FAST で評価
### Phase 39 実施済みFAST v3
以下の gate function は Phase 39 で定数化済み:
**malloc path実施済み:**
| Gate | File | FAST v3 値 | Status |
|------|------|-----------|--------|
| `front_gate_unified_enabled()` | malloc_tiny_fast.h | 固定 1 | ✅ GO |
| `alloc_dualhot_enabled()` | malloc_tiny_fast.h | 固定 0 | ✅ GO |
**free path実施済み:**
| Gate | File | FAST v3 値 | Status |
|------|------|-----------|--------|
| `g_bench_fast_front` | hak_free_api.inc.h | compile-out | ✅ GO |
| `g_v3_enabled` | hak_free_api.inc.h | compile-out | ✅ GO |
| `g_free_dispatch_ssot` | hak_free_api.inc.h | lazy-init 維持 | 保留 |
**stats実施済み:**
| Gate | File | FAST v3 値 | Status |
|------|------|-----------|--------|
| `free_dispatch_stats_enabled()` | free_dispatch_stats_box.h | 固定 false | ✅ GO |
**Phase 39 結果:** +1.98%GO