Go プロジェクトのパフォーマンスを計測・分析し、改善案を提示します。performance-optimizer エージェントと連携して最適化を実行。
Measures Go project performance, analyzes bottlenecks, and suggests optimizations with benchmarks.
/plugin marketplace add shiiman/claude-code-plugins/plugin install shiiman-go@shiiman-claude-code-pluginsGo プロジェクトのパフォーマンスを計測・分析し、改善案を提示します。performance-optimizer エージェントと連携して最適化を実行。
/shiiman-go:perf
/shiiman-go:perf ./internal/handler
/shiiman-go:perf --bench
/shiiman-go:perf --help
| オプション | 説明 |
|---|---|
--bench | ベンチマークのみ実行 |
--profile | プロファイリングを実行 |
--help | このコマンドのヘルプを表示 |
--help が指定された場合: このファイルの内容を要約して表示し、終了。
1. 対象コードの特定
↓
2. ベースライン測定
↓
3. ボトルネック分析
↓
4. 改善案提示
↓
5. ユーザーと方針決定
↓
6. 修正実装
↓
7. 効果測定
# 基本的なベンチマーク
go test -bench=. -benchmem ./...
# 特定パッケージのベンチマーク
go test -bench=. -benchmem ./internal/handler
# 複数回実行して安定した結果を取得
go test -bench=. -benchmem -count=3 ./... | tee baseline.txt
# CPU プロファイル
go test -bench=. -cpuprofile=cpu.prof ./...
go tool pprof cpu.prof
# メモリプロファイル
go test -bench=. -memprofile=mem.prof ./...
go tool pprof mem.prof
# pprof コマンド
# top - 実行時間が最も長い関数を表示
# list - 特定関数のソースコード行ごとの分析
# web - グラフ形式で可視化
## パフォーマンス分析結果
### ベンチマーク結果
- BenchmarkXxx: {N} ns/op
- メモリアロケーション: {M} B/op
- アロケーション回数: {K} allocs/op
### 特定されたボトルネック
1. {関数名}: {問題の説明}
2. {関数名}: {問題の説明}
### 改善案
| 提案 | 内容 | 期待される改善 |
|------|------|---------------|
| 1 | {改善内容} | {効果} |
| 2 | {改善内容} | {効果} |
どの改善案を適用しますか?
| 観点 | 改善例 |
|---|---|
| データ構造 | slice、map の適切な選択 |
| アルゴリズム | 計算量の削減、キャッシング |
| 並行処理 | goroutine、channel、ワーカープール |
| メモリ管理 | sync.Pool、スライスの事前確保 |
| 文字列操作 | strings.Builder の使用 |
| PGO | Profile-Guided Optimization(Go 1.22+) |
| 最適化内容 | 期待される改善率 |
|---|---|
| スライスの事前確保 | メモリ 30-50% 削減 |
| ポインタレシーバ | CPU 20-40% 高速化 |
| strings.Builder | 文字列操作 2-5x 高速化 |
| sync.Pool | アロケーション 50-80% 削減 |
| 並行処理最適化 | スループット 2-10x 向上 |
| PGO | 全体 2-14% 高速化 |
# 最適化前
go test -bench=. -benchmem -count=3 ./... | tee before.txt
# 最適化後
go test -bench=. -benchmem -count=3 ./... | tee after.txt
# 比較
benchstat before.txt after.txt