Back to list
ShunsukeHayashi

performance-analysis-and-optimization

by ShunsukeHayashi

🤖 First open-source, economically-governed, beginner-friendly autonomous development framework built on Issue-Driven Development | 超初心者でも使える自律型開発フレームワーク

13🍴 8📅 Jan 24, 2026

SKILL.md


name: Performance Analysis and Optimization description: CPU profiling, benchmarking, and memory analysis for Rust applications. Use when code is slow, memory usage is high, or optimization is needed. allowed-tools: Bash, Read, Grep, Glob

⚡ Performance Analysis and Optimization

Version: 2.0.0 Last Updated: 2025-11-22 Priority: ⭐⭐⭐ (P2 Level) Purpose: Rustアプリケーションのパフォーマンス分析と最適化


📋 概要

CPUプロファイリング、ベンチマーク、メモリ分析を通じた パフォーマンス問題の特定と最適化を提供します。


🎯 P0: 呼び出しトリガー

トリガー
遅い"this is slow"
メモリ使用"why is memory usage so high?"
最適化"optimize this function"
プロファイリング"profile this code"
ベンチマーク"benchmark performance"

🔧 P1: 分析ツール一覧

ツール優先順位

ツール用途対象コマンド
criterionベンチマーク関数cargo bench
flamegraphCPUプロファイルプロセスcargo flamegraph
perf詳細プロファイルLinuxperf record
valgrindメモリヒープvalgrind --tool=massif
heaptrackヒープ追跡割り当てheaptrack ./binary
cargo-bloatバイナリサイズサイズcargo bloat
tokio-console非同期タスクtokio-console

🚀 P2: 分析パターン

Pattern 1: ベンチマーク(criterion)

// benches/my_benchmark.rs
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn bench_function(c: &mut Criterion) {
    c.bench_function("my_function", |b| {
        b.iter(|| my_function(black_box(input)))
    });
}

criterion_group!(benches, bench_function);
criterion_main!(benches);
cargo bench

Pattern 2: Flamegraph

# フレームグラフ生成
cargo flamegraph --bin miyabi -- --issue 270

# 出力: flamegraph.svg

Pattern 3: メモリプロファイル

# valgrind massif
valgrind --tool=massif ./target/release/miyabi
ms_print massif.out.*

# heaptrack(推奨)
heaptrack ./target/release/miyabi
heaptrack_gui heaptrack.miyabi.*

Pattern 4: バイナリサイズ分析

# サイズ分析
cargo bloat --release --crates

# シンボル別
cargo bloat --release -n 20

⚡ P3: 最適化戦略

最適化優先順位

優先度戦略効果難易度
1アルゴリズム改善
2データ構造変更
3メモリ割り当て削減
4並列化
5キャッシュ活用
6SIMD/低レベル

よくある最適化

// ❌ 毎回allocate
for item in items {
    let s = item.to_string();
    // ...
}

// ✅ 事前allocate
let mut buf = String::with_capacity(1024);
for item in items {
    buf.clear();
    write!(&mut buf, "{}", item).unwrap();
    // ...
}
// ❌ Clone多用
fn process(data: Vec<T>) -> Vec<T> {
    data.clone()
}

// ✅ 参照で渡す
fn process(data: &[T]) -> Vec<T> {
    // ...
}

📊 パフォーマンス目標

メトリクス目標測定方法
ビルド時間<5分CI計測
テスト時間<2分cargo test
バイナリサイズ<50MBcargo bloat
メモリ使用量<500MBruntime計測

🛡️ 注意事項

リリースビルドで測定

# ❌ デバッグビルド(遅い)
cargo run

# ✅ リリースビルド
cargo run --release

PGO(Profile-Guided Optimization)

# Step 1: インストルメント
RUSTFLAGS="-Cprofile-generate=/tmp/pgo" cargo build --release

# Step 2: プロファイル収集
./target/release/miyabi [typical workload]

# Step 3: 最適化ビルド
llvm-profdata merge -o /tmp/pgo/merged.profdata /tmp/pgo
RUSTFLAGS="-Cprofile-use=/tmp/pgo/merged.profdata" cargo build --release

✅ 成功基準

チェック項目基準
ボトルネック特定上位3箇所
ベンチマーク改善前後比較
メモリリークなし
回帰テストパフォーマンス維持

🔗 関連Skills

  • Rust Development: ビルド最適化
  • Debugging: 問題箇所特定
  • Security Audit: セキュリティとのトレードオフ

Score

Total Score

75/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

+10
人気

GitHub Stars 100以上

0/15
最近の活動

1ヶ月以内に更新

+10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

+5

Reviews

💬

Reviews coming soon