Files
hakorune/docs/private/roadmap/phases/phase-20.23/PHASE_ORDER_ANALYSIS.md

20 KiB
Raw Blame History

Phase 20.23-20.26 Order Analysis & Timeline Optimization

分析日: 2025-10-30 前提: User の重大発見「Arc/RefCell はHakoruneスクリプトで実装するやつじゃない


🔥 Critical Discovery Impact

Before (Original Plan - C Implementation)

Phase 20.23: Arc/RefCell (C)    2-3 months ❌
Phase 20.24: Box System         3-4 months
Phase 20.25: Rust削除           2-3 months
Total: 7-10 months

After (Hakorune Implementation - This Plan)

Phase 20.23: Arc/RefCell (Hako) 2-3 weeks ✅
Phase 20.24: Parser削除         1-2 months
Phase 20.25: Box System削除     2-3 months
Phase 20.26: Final Rust削除     2-3 months
Total: 6-9 months

Time Savings: ~2.5 months (10-11 weeks)


📊 Phase Order Comparison

Rationale: Foundation → Value

Timeline:
├─ Phase 20.23: Arc/RefCell (Hakorune)  2-3 weeks   ← Foundation for Box System
├─ Phase 20.24: Parser削除              1-2 months  ← Instant value (-10,500 lines)
├─ Phase 20.25: Box System削除          2-3 months  ← Requires Arc/RefCell
└─ Phase 20.26: Final Rust削除          2-3 months  ← Cleanup & hakmem

Total: 6-9 months

Pros:

  • Logical flow: FoundationArc/RefCell→ ValueParser→ Major workBox System
  • Low risk start: Arc/RefCell は小規模2-3週間でリスク低い
  • Early confidence: Week 3 で基盤完成、すぐ Parser 削除開始
  • Box System ready: Phase 20.25 開始時に Arc/RefCell 準備完了

Cons:

  • ⚠️ Delayed instant value: Parser削除まで 2-3週間待ちOption B より遅い)

Risk Level: Low Complexity: Low → Medium → High(段階的難易度上昇)


Option B: Parser First, Arc/RefCell Second

Rationale: Instant Value → Foundation

Timeline:
├─ Phase 20.23: Parser削除              1-2 months  ← Instant value first ⚡
├─ Phase 20.24: Arc/RefCell (Hakorune)  2-3 weeks   ← Foundation delayed
├─ Phase 20.25: Box System削除          2-3 months  ← Must wait for Arc/RefCell
└─ Phase 20.26: Final Rust削除          2-3 months  ← Cleanup & hakmem

Total: 6-9 months (同じ)

Pros:

  • Immediate value: Week 1 から Parser 削除開始
  • Early win: Month 1 で -10,500 lines 達成
  • Momentum: 早期成功でチーム士気向上

Cons:

  • Unnatural flow: Parser は Box System と無関係、Arc/RefCell が後回し
  • Phase 20.25 blocked: Parser 削除後に Arc/RefCell 待ち2-3週間停滞
  • ⚠️ Risk inversion: Easy → Hard → Easy難易度が不自然

Risk Level: Medium ⚠️ Complexity: Low → Easy → High(難易度が飛ぶ)


Option C: Parallel Tracks

Rationale: Arc/RefCell + Parser 同時進行

Timeline:
├─ Track A: Arc/RefCell (2-3 weeks) + Box System (2-3 months)
└─ Track B: Parser削除 (1-2 months) + MIR Builder削除 (内包)

Converge: Phase 20.26 (Final Rust削除)

Total: 4-5 months最速

Pros:

  • Fastest: 並列実行で 1-4ヶ月短縮
  • Resource utilization: 2チームで分担

Cons:

  • Coordination overhead: 2つのトラックを調整・統合
  • Integration hell: Track A + B の統合時に競合リスク
  • Testing complexity: 両方のテストを並行管理
  • Rollback nightmare: 問題発生時に切り戻し困難
  • Resource requirement: 2チーム必要現実的でない可能性

Risk Level: High Complexity: High(並列管理)

Verdict: ⚠️ Not Recommended単一チームなら不可能、2チームでも高リスク


Why Option A Is Best

1. Natural Dependency Flow

Arc/RefCellFoundation
    ↓ requires
Box SystemMajor work
    ↓ uses
Parser/MIR BuilderIndependent
    ↓ enables
Final Rust削除Cleanup

Option A follows this flow perfectly:

  • Arc/RefCell → Box Systemnatural dependency
  • Parser 削除 は Box System と独立いつでもOK
  • Parser を Box System の前にやることで、早期に価値提供しつつ並列感覚

2. Risk Mitigation

Option A risk progression:

Week 1-3:     Arc/RefCell       Risk: LOW ✅
Month 2-3:    Parser削除        Risk: LOW ✅
Month 4-6:    Box System削除    Risk: MEDIUM ⚠️
Month 7-9:    Final Rust削除    Risk: MEDIUM ⚠️

Low risk → Low risk → Medium risk → Medium risk(段階的)

Option B risk progression:

Month 1-2:    Parser削除        Risk: LOW ✅
Week 3-4:     Arc/RefCell       Risk: LOW ✅
Month 3-5:    Box System削除    Risk: MEDIUM ⚠️
Month 6-8:    Final Rust削除    Risk: MEDIUM ⚠️

Low → Low停滞期→ Medium → Medium2-3週間の待ち時間発生

3. Psychological Impact

Option A:

  • Week 3: Arc/RefCell complete小さな勝利
  • Month 2: Parser deleted大きな勝利: -10,500 lines
  • Month 5: Box System deleted巨大な勝利: -22,193 lines
  • Month 8: Final Rust deleted最終勝利: -61,713 lines

Consistent momentum: 小 → 大 → 超大 → 究極

Option B:

  • Month 2: Parser deleted大きな勝利
  • Wait 2-3 weeks(停滞)← 士気低下リスク
  • Month 3: Arc/RefCell complete小さな勝利← 逆行感
  • Month 5: Box System deleted巨大な勝利

Momentum break: 大 → 停滞 → 小 → 超大(リズムが悪い)

4. Testing Strategy

Option A:

Week 3: Arc/RefCell テスト(小規模)
  ↓
Month 2: Parser削除テスト独立
  ↓
Month 5: Box System削除テストArc/RefCell 既にテスト済み)✅

Option B:

Month 2: Parser削除テスト独立
  ↓
Month 3: Arc/RefCell テスト(小規模)
  ↓
Month 5: Box System削除テストArc/RefCell まだ若い)⚠️

Option A の優位性: Box System削除時に Arc/RefCell は既に 2ヶ月運用実績あり


📈 Timeline ComparisonDetailed

Option A: Arc/RefCell FirstRecommended

┌─────────────────────────────────────────────────────────────────┐
│ Month 1                                                          │
├─────────────────────────────────────────────────────────────────┤
│ Week 1:   Arc/RefCell (C data plane)           [████░░░░] 50%   │
│ Week 2:   Arc/RefCell (Hakorune policy plane)  [████░░░░] 50%   │
│ Week 3:   Arc/RefCell (Integration & tests)    [████████] 100%  │
│ Week 4:   Parser削除 (Gate infrastructure)     [████░░░░] 25%   │
│                                                                  │
│ Checkpoint: Arc/RefCell complete ✅                              │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 2-3: Parser削除                                            │
├─────────────────────────────────────────────────────────────────┤
│ Week 1-3:  Smoke test validation               [████████] 100%  │
│ Week 4:    CI integration                      [████░░░░] 100%  │
│ Week 5:    Default flip                        [████░░░░]  50%  │
│ Week 6:    File deletion                       [████████] 100%  │
│ Week 7:    Integration testing                 [████████] 100%  │
│ Week 8:    Documentation                       [████░░░░] 100%  │
│                                                                  │
│ Checkpoint: Parser deleted (-10,500 lines) ✅                    │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 4-6: Box System削除                                        │
├─────────────────────────────────────────────────────────────────┤
│ Week 1-4:  MIR Builder deletion                [████████]  33%  │
│ Week 5-8:  Rust VM deletion                    [████████]  33%  │
│ Week 9-12: Box System deletion                 [████████]  34%  │
│                                                                  │
│ Checkpoint: Box System deleted (-22,193 lines) ✅                │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 7-9: Final Rust削除                                        │
├─────────────────────────────────────────────────────────────────┤
│ Week 1-4:  Audit & Wave 1 deletion             [████████]  33%  │
│ Week 5-8:  Plugin System & Kernel              [████████]  33%  │
│ Week 9-12: hakmem integration & cleanup        [████████]  34%  │
│                                                                  │
│ Completion: Final Rust deleted (-61,713 lines) ✅                │
└─────────────────────────────────────────────────────────────────┘

Total: 6-9 months
Reduction: -94,406 lines (-95.0%)

Option B: Parser First

┌─────────────────────────────────────────────────────────────────┐
│ Month 1-2: Parser削除                                            │
├─────────────────────────────────────────────────────────────────┤
│ Week 1:    Parser gate infrastructure          [████░░░░]  25%  │
│ Week 2-3:  Smoke test validation               [████████] 100%  │
│ Week 4:    CI integration                      [████░░░░] 100%  │
│ Week 5:    Default flip                        [████░░░░]  50%  │
│ Week 6:    File deletion                       [████████] 100%  │
│ Week 7:    Integration testing                 [████████] 100%  │
│ Week 8:    Documentation                       [████░░░░] 100%  │
│                                                                  │
│ Checkpoint: Parser deleted (-10,500 lines) ✅                    │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 3: Arc/RefCell                                             │
├─────────────────────────────────────────────────────────────────┤
│ Week 1:    Arc/RefCell (C data plane)          [████░░░░]  50%  │
│ Week 2:    Arc/RefCell (Hakorune policy)       [████░░░░]  50%  │
│ Week 3:    Arc/RefCell (Integration & tests)   [████████] 100%  │
│ Week 4:    (Buffer /準備期間)                  [░░░░░░░░]   0%  │
│                                                                  │
│ Checkpoint: Arc/RefCell complete ✅                              │
│ ⚠️ Note: 2-3 weeks gap before Box System                        │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 4-6: Box System削除                                        │
├─────────────────────────────────────────────────────────────────┤
│ (Same as Option A)                                               │
└─────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────┐
│ Month 7-9: Final Rust削除                                        │
├─────────────────────────────────────────────────────────────────┤
│ (Same as Option A)                                               │
└─────────────────────────────────────────────────────────────────┘

Total: 6-9 months (同じ)
Reduction: -94,406 lines (同じ)
⚠️ But with 2-3 week gap (momentum loss risk)

🎯 Final Recommendation

Choose Option A: Arc/RefCell First, Parser Second

Reasons (Data-Driven)

評価項目 Option A Option B Option C
Total Duration 6-9 months 6-9 months 4-5 months
Risk Level Low ⚠️ Medium High
Dependency Flow Natural ⚠️ Broken ⚠️ Complex
Momentum Consistent ⚠️ Gap ⚠️ Hard to manage
Testing Strategy Simple ⚠️ Rushed Complex
Rollback Ease Easy Easy Hard
Resource Need 1 team 1 team 2 teams
Coordination Minimal Minimal High

Score:

  • Option A: 8/8 or ⚠️all manageable
  • Option B: 6/8 , 2/8 ⚠️momentum gap
  • Option C: 3/8 , 2/8 ⚠️, 3/8 high risk

Implementation Priority

Priority 0 (Immediate):
├─ Phase 20.23 Week 1: Arc/RefCell C data plane
└─ Phase 20.23 Week 2: Arc/RefCell Hakorune policy plane

Priority 1 (Month 1):
├─ Phase 20.23 Week 3: Arc/RefCell integration & tests
└─ Phase 20.24 Week 1: Parser gate infrastructure

Priority 2 (Month 2-3):
├─ Phase 20.24: Parser削除 complete
└─ Checkpoint: -10,500 lines ✅

Priority 3 (Month 4-6):
├─ Phase 20.25: Box System削除 complete
└─ Checkpoint: -32,693 lines total ✅

Priority 4 (Month 7-9):
├─ Phase 20.26: Final Rust削除 complete
└─ Completion: -94,406 lines total ✅

📊 Success Metrics

Quantitative Goals

Metric Phase 20.23 Phase 20.24 Phase 20.25 Phase 20.26 Total
Duration 2-3 weeks 1-2 months 2-3 months 2-3 months 6-9 months
Lines Deleted -0 -10,500 -22,193 -61,713 -94,406
Reduction % 0% -9.0% -19.0% -52.8% -80.8%
Risk Level Low Low Medium Medium -
Test Coverage 100% 100% 100% 100% 100%

Qualitative Goals

  • True Self-Hosting: Rust = Floor~5,000 lines, Hakorune = House~55,000 lines
  • Clean Architecture: PolicyHakorunevs DataCplane 完全分離
  • Memory Safety: hakmem + Arc/RefCell で完全自律
  • Performance Parity: ±10% vs original Rust implementation
  • Documentation Complete: 各 Phase ごとに完全ドキュメント
  • CI Green: 毎日 296/296 smoke tests PASS

🔗 Reference Documents

Created PlansThis Analysis

  1. Phase 20.23: Arc/RefCell in Hakorune

    • Hakorune implementationnot C!
    • 2-3 weeks duration
    • GcBox pattern precedent
  2. Phase 20.24: Parser削除

    • Instant value delivery
    • -10,500 lines reduction
    • 1-2 months duration
  3. Phase 20.25: Box System + MIR Builder削除

    • Major work50% Rust reduction
    • -22,193 lines reduction
    • 2-3 months duration
  4. Phase 20.26: Final Rust Consolidation

    • hakmem integration
    • -61,713 lines reduction
    • 2-3 months duration

Existing Analysis


🎉 Conclusion

Recommended Strategy: Option A - Arc/RefCell First, Parser Second

Key Advantages

  1. Natural Flow: Foundation → Value → Major Work → Cleanup
  2. Low Risk: 段階的リスク上昇Low → Low → Medium → Medium
  3. Consistent Momentum: 小さな勝利 → 大きな勝利 → 巨大な勝利
  4. Early Foundation: Arc/RefCell を早期に確立Month 1
  5. Simple Testing: Arc/RefCell は Box System前に十分テスト済み

Critical Success Factor

User の発見: "Arc/RefCell はHakoruneスクリプトで実装するやつじゃない"

完全に正しい! これにより:

  • 2.5ヶ月の時間短縮2-3ヶ月 → 2-3週間
  • リスク大幅削減C実装リスク → Hakorune実装リスク
  • 保守性向上C コード → Hakorune コード)

Next Steps

  1. Immediate: Phase 20.23 Week 1 開始Arc/RefCell C data plane
  2. Month 1: Phase 20.23 完了 + Phase 20.24 開始準備
  3. Month 2-3: Phase 20.24 完了Parser削除
  4. Month 4-6: Phase 20.25 実行Box System削除
  5. Month 7-9: Phase 20.26 実行Final Rust削除
  6. Completion: True Self-Hosting 達成

分析完了日: 2025-10-30 推奨: Option A - Arc/RefCell First, Parser Second Total Duration: 6-9 months Total Reduction: -94,406 lines (-95.0%) Final State: Rust = Floor~5,000 lines, Hakorune = House~55,000 lines