Files
hakorune/docs/development/roadmap/phases/phase-21.5-optimization
nyash-codex 8214176814 feat(perf): add Phase 21.8 foundation for IntArrayCore/MatI64 numeric boxes
Prepare infrastructure for specialized numeric array benchmarking:
- Add IntArrayCore plugin stub (crates/nyash_kernel/src/plugin/intarray.rs)
- Add IntArrayCore/MatI64 box definitions (lang/src/runtime/numeric/)
- Add Phase 21.8 documentation and task tracking
- Update nyash.toml/hako.toml with numeric library configuration
- Extend microbench.sh for matmul_core benchmark case

Next: Resolve Stage-B MirBuilder to recognize MatI64/IntArrayCore as boxes

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-14 15:18:14 +09:00
..

Phase 21.5 — Optimization (AotPrepFirst)

目的

  • .hako 側AotPrepで前処理最適化構造のみを行い、LLVM/AOT に渡すIRを軽量にする。
  • 既定は挙動不変optin。Return 純化ガードで安全性を担保。

チェックリスト21.5 時点の着地)

  • パス分割StrlenFold / LoopHoist / ConstDedup / CollectionsHot / BinopCSE
  • CollectionsHotArray/Map導入既定OFF
  • Map key モード NYASH_AOT_MAP_KEY_MODE={h|i64|hh|auto}
  • LoopHoist v1 / BinopCSE v1最小
  • ベンチ linidx/maplin 追加
  • LoopHoist v2+/* 右項 const の連鎖前出し/fixpoint
  • BinopCSE v2線形 i*n 共通化の強化)
  • CollectionsHot v2array index の共通SSA利用
  • Map auto 精緻化_is_const_or_linear の再帰判定)
  • Idempotence置換済みタグで再実行時も不変
  • arraymap/matmul ≤ 125%C基準

メモ21.5 クロージング)

  • linidx/maplin など「線形インデックスArray/Map」系は CollectionsHot + hoist/CSE で C≒100% 近辺まで到達。
  • arraymap は Array/Map 部分の externcall 化は進んだものの、文字列キー生成toString/\"k\"+idx)と hash パスが支配的なため、C の単純 int[] とは根本的に前提が異なる状態で終了。
  • matmul は CollectionsHot 自体は単体では効いているが、行列積そのものが ArrayBox ベースであり、Core 数値箱不在のまま 80% 目標には届かず。これは 21.6 以降の「Core 数値箱+行列箱」導入で扱う。

トグル

  • NYASH_MIR_LOOP_HOIST=1 … StrlenFold/LoopHoist/ConstDedup/BinopCSE を有効化
  • NYASH_AOT_COLLECTIONS_HOT=1 … CollectionsHotArray/Map
  • NYASH_AOT_MAP_KEY_MODEh|i64|hh|auto(推奨: auto
  • NYASH_VERIFY_RET_PURITY=1 … Return 純化ガード開発時ON

ベンチ(例)

export NYASH_SKIP_TOML_ENV=1 NYASH_DISABLE_PLUGINS=1 \
       NYASH_LLVM_SKIP_BUILD=1 NYASH_LLVM_FAST=1 NYASH_LLVM_FAST_INT=1 \
       NYASH_MIR_LOOP_HOIST=1 NYASH_AOT_COLLECTIONS_HOT=1 NYASH_VERIFY_RET_PURITY=1
for c in arraymap matmul sieve linidx maplin; do \
  tools/perf/microbench.sh --case $c --exe --runs 3; echo; done