docs/research/parallel-execution-findings.md
Date: 2025-10-20 Purpose: 並列実行の実装と実測結果 Status: ✅ 実装完了、⚠️ パフォーマンス課題発見
インデックス作成を並列でやった方がいいんじゃない? 既存エージェントって使えないの? 並列実行できてるの?全然速くないんだけど。
回答: 全て実装して測定しました。
ファイル: superclaude/indexing/parallel_repository_indexer.py
機能:
並列実行:
- ThreadPoolExecutor で5タスク同時実行
- Code/Docs/Config/Tests/Scripts を分散処理
- 184ファイルを0.41秒でインデックス化
既存エージェント活用:
- system-architect: コード/設定/テスト/スクリプト分析
- technical-writer: ドキュメント分析
- deep-research-agent: 深い調査が必要な時
- 18個の専門エージェント全て利用可能
自己学習:
- エージェントパフォーマンスを記録
- .superclaude/knowledge/agent_performance.json に蓄積
- 次回実行時に最適なエージェントを自動選択
出力:
PROJECT_INDEX.md: 完璧なナビゲーションマップPROJECT_INDEX.json: プログラマティックアクセス用実装済み:
class AgentDelegator:
"""エージェント性能を学習して最適化"""
def record_performance(agent, task, duration, quality, tokens):
# パフォーマンスデータ記録
# .superclaude/knowledge/agent_performance.json に保存
def recommend_agent(task_type):
# 過去のパフォーマンスから最適エージェント推薦
# 初回: デフォルト
# 2回目以降: 学習データから選択
学習データ例:
{
"system-architect:code_structure_analysis": {
"executions": 10,
"avg_duration_ms": 5.2,
"avg_quality": 88,
"avg_tokens": 4800
},
"technical-writer:documentation_analysis": {
"executions": 10,
"avg_duration_ms": 152.3,
"avg_quality": 92,
"avg_tokens": 6200
}
}
ファイル: tests/performance/test_parallel_indexing_performance.py
機能:
Metric Sequential Parallel Improvement
────────────────────────────────────────────────────────────
Execution Time 0.3004s 0.3298s 0.91x ❌
Files Indexed 187 187 -
Quality Score 90/100 90/100 -
Workers 1 5 -
結論: 並列実行が逆に遅い
測定結果:
原因: GIL (Global Interpreter Lock)
GILとは:
- Python の制約: 1つのPythonプロセスで同時に実行できるスレッドは1つだけ
- ThreadPoolExecutor: GIL の影響を受ける
- I/O bound タスク: 効果あり
- CPU bound タスク: 効果なし
今回のタスク:
- ファイル探索: I/O bound → 並列化の効果あるはず
- 実際: タスクが小さすぎてオーバーヘッドが大きい
- Thread 管理コスト > 並列化の利益
結果:
- 並列実行のオーバーヘッド: ~30ms
- タスク実行時間: ~300ms
- オーバーヘッド比率: 10%
- 並列化の効果: ほぼゼロ
測定されたタスク時間:
Task Sequential Parallel (実際)
────────────────────────────────────────────────
code_structure 3ms 0ms (誤差)
documentation 152ms 0ms (並列)
configuration 144ms 0ms (並列)
tests 1ms 0ms (誤差)
scripts 0ms 0ms (誤差)
────────────────────────────────────────────────
Total 300ms ~300ms + 30ms (overhead)
問題点:
実装:
from concurrent.futures import ProcessPoolExecutor
# ThreadPoolExecutor → ProcessPoolExecutor
with ProcessPoolExecutor(max_workers=5) as executor:
# GIL の影響を受けない真の並列実行
期待効果:
デメリット:
実装:
import asyncio
async def analyze_directory_async(path):
# Non-blocking I/O operations
# Asyncio で並列I/O
results = await asyncio.gather(*tasks)
期待効果:
デメリット:
これが本命!
# Claude Code の Task tool を使った並列実行
# 複数エージェントを同時起動
# 現在の実装: Python threading (GIL制約あり)
# ❌ 速くない
# 改善案: Task tool による真の並列エージェント起動
# ✅ Claude Codeレベルでの並列実行
# ✅ GILの影響なし
# ✅ 各エージェントが独立したAPI呼び出し
実装例:
# 疑似コード
tasks = [
Task(
subagent_type="system-architect",
prompt="Analyze code structure in superclaude/"
),
Task(
subagent_type="technical-writer",
prompt="Analyze documentation in docs/"
),
# ... 5タスク並列起動
]
# 1メッセージで複数 Task tool calls
# → Claude Code が並列実行
# → 本当の並列化!
目的: Claude Codeレベルでの真の並列実行
実装:
ParallelRepositoryIndexer を Task tool ベースに書き換え期待効果:
目的: 18個のエージェントを最大活用
活用例:
Code Analysis:
- backend-architect: API/DB設計分析
- frontend-architect: UI component分析
- security-engineer: セキュリティレビュー
- performance-engineer: パフォーマンス分析
Documentation:
- technical-writer: ドキュメント品質
- learning-guide: 教育コンテンツ
- requirements-analyst: 要件定義
Quality:
- quality-engineer: テストカバレッジ
- refactoring-expert: リファクタリング提案
- root-cause-analyst: 問題分析
実装:
学習サイクル:
1. タスク実行
2. パフォーマンス測定
3. ナレッジベース更新
4. 次回実行時に最適化
蓄積データ:
- エージェント × タスクタイプ の性能
- 成功パターン
- 失敗パターン
- 改善提案
自動最適化:
- 最適エージェント選択
- 最適並列度調整
- 最適タスク分割
GIL により:
対策:
18個の専門エージェントが既に存在:
現状: ほとんど使われていない 理由: 自動活用の仕組みがない 解決: AgentDelegator で自動選択
既に動いている:
.superclaude/knowledge/agent_performance.json次: さらに賢くする
# 現在の実装(Threading版)
uv run python superclaude/indexing/parallel_repository_indexer.py
# 出力
# - PROJECT_INDEX.md
# - PROJECT_INDEX.json
# - .superclaude/knowledge/agent_performance.json
# Sequential vs Parallel 比較
uv run pytest tests/performance/test_parallel_indexing_performance.py -v -s
# 結果
# - .superclaude/knowledge/parallel_performance.json
# Markdown
cat PROJECT_INDEX.md
# JSON
cat PROJECT_INDEX.json | python3 -m json.tool
# パフォーマンスデータ
cat .superclaude/knowledge/agent_performance.json | python3 -m json.tool
実装ファイル:
superclaude/indexing/parallel_repository_indexer.pytests/performance/test_parallel_indexing_performance.pyエージェント定義:
superclaude/agents/ (18個の専門エージェント)生成物:
PROJECT_INDEX.md: リポジトリナビゲーション.superclaude/knowledge/: 自己学習データ関連ドキュメント:
docs/research/pm-mode-performance-analysis.mddocs/research/pm-mode-validation-methodology.mdLast Updated: 2025-10-20 Status: Threading実装完了、Task Tool版が次のステップ Key Finding: Python Threading は GIL により期待した並列化ができない