CURRENT_TASK: Registry 線形スキャン ボトルネック特定 (2025-11-05)
- perf 分析で superslab_refill が 28.51% CPU を消費 - Root cause: 262,144 エントリの線形スキャン (97.65% の hot instructions) - 解決策: per-class registry (8×4096 = 32K entries) - 期待効果: +200-300% (2.59M → 7.8-10.4M ops/s) - Box Refactor は既に動いている (+463% ST, +131% MT) 次のアクション: Phase 1 実装 (per-class registry 変更) 詳細: PERF_ANALYSIS_2025_11_05.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1,4 +1,80 @@
|
|||||||
# Current Task (2025-11-04)
|
# Current Task (2025-11-05)
|
||||||
|
|
||||||
|
## 🔔 最新アップデート (2025-11-05 16:30) 🔥🔥🔥
|
||||||
|
|
||||||
|
### ✅ Registry 線形スキャン ボトルネック特定!
|
||||||
|
|
||||||
|
**Perf 分析完了 → Root Cause 発見!**
|
||||||
|
|
||||||
|
**測定結果 (Larson, threads=4):**
|
||||||
|
```
|
||||||
|
HAKMEM: 3.62M ops/s (21.6% of system)
|
||||||
|
System: 16.76M ops/s (100%)
|
||||||
|
差: -78.4% 💀
|
||||||
|
```
|
||||||
|
|
||||||
|
**Perf プロファイリング結果:**
|
||||||
|
```
|
||||||
|
28.51% superslab_refill 💀💀💀 圧倒的ボトルネック
|
||||||
|
2.58% exercise_heap (ベンチマーク本体)
|
||||||
|
```
|
||||||
|
|
||||||
|
**問題:** アロケータ (superslab_refill) がベンチマーク本体 (exercise_heap) より CPU time を消費!
|
||||||
|
|
||||||
|
**Hot Instructions 分析 (perf annotate):**
|
||||||
|
```
|
||||||
|
32.36% cmp $0x3ffff,%r11d ← 262,143 回ループ!
|
||||||
|
16.78% inc %r13d ← カウンタ++
|
||||||
|
16.29% add $0x18,%rbx ← ポインタ進める
|
||||||
|
合計 97.65% の CPU time がループに集中
|
||||||
|
```
|
||||||
|
|
||||||
|
**Root Cause (core/hakmem_tiny_free.inc:917):**
|
||||||
|
```c
|
||||||
|
for (int i = 0; i < SUPER_REG_SIZE && scanned < scan_max; i++) {
|
||||||
|
// ^^^^^^^^^^^ 262,144 エントリを線形スキャン!
|
||||||
|
SuperRegEntry* e = &g_super_reg[i];
|
||||||
|
// ... class_idx 不一致でも全エントリをイテレート
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**解決策: Per-class Registry**
|
||||||
|
```c
|
||||||
|
// Before: 全 class 混在
|
||||||
|
SuperRegEntry g_super_reg[262144];
|
||||||
|
|
||||||
|
// After: class ごとに分離
|
||||||
|
SuperRegEntry g_super_reg_by_class[TINY_NUM_CLASSES][4096];
|
||||||
|
// 8 classes × 4096 entries = 32K total
|
||||||
|
```
|
||||||
|
|
||||||
|
**期待効果:**
|
||||||
|
- スキャン対象: 262,144 → 4,096 エントリ (-98.4%)
|
||||||
|
- **期待改善: +200-300%** (2.59M → 7.8-10.4M ops/s)
|
||||||
|
- **System malloc の 54-73% まで到達可能!** 🎯
|
||||||
|
|
||||||
|
**詳細レポート:**
|
||||||
|
- `PERF_ANALYSIS_2025_11_05.md` - 完全分析 + 実装プラン
|
||||||
|
- Commit: `859027e` "Perf Analysis: Registry 線形スキャンがボトルネック"
|
||||||
|
- Branch: `perf-analysis-2025-11-05` (pushed to private repo)
|
||||||
|
|
||||||
|
**次のアクション:**
|
||||||
|
1. **Phase 1 実装** (1-2日): per-class registry に変更
|
||||||
|
- `core/hakmem_super_registry.{h,c}` 構造変更
|
||||||
|
- `core/hakmem_tiny_free.inc:917` スキャン簡素化
|
||||||
|
- 目標: 2.59M → 7.8M ops/s (+3倍!)
|
||||||
|
|
||||||
|
2. **Phase 2 実装** (追加 1日): 早期終了 + First-fit
|
||||||
|
- 最初の freelist 発見で即 return
|
||||||
|
- 目標: 7.8M → 11.7M ops/s (system の 82%!)
|
||||||
|
|
||||||
|
**重要:** Box Refactor は既に動いている!
|
||||||
|
- Single-thread: 0.46M → 2.59M ops/s (+463%!) ✅
|
||||||
|
- Multi-thread: 1.81M → 4.19M ops/s (+131%!) ✅
|
||||||
|
- 外部AIの最適化も効いている (Option A: Inline TLS cache access)
|
||||||
|
- **ただし Registry スキャンがボトルネックで system には届かず**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 🔔 最新アップデート (2025-11-06 23:xx)
|
## 🔔 最新アップデート (2025-11-06 23:xx)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user