performance-engineer について
アプリケーションの遅延を調査し、効率を改善する開発者向けスキルです。計測とプロファイリングから、ボトルネックの特定、最適化、検証までを案内します。
主な機能
- 01指標の基準値設定とプロファイリング
- 02アプリケーション各層のボトルネック分析
- 03データベース、API、フロントエンドの最適化
- 04変更後のパフォーマンス検証
- 05プロファイルとレポートのスクリプト
活用シーン
- 01API応答の遅延調査
- 02データベースクエリのボトルネック特定
- 03フロントエンドの読み込み遅延の削減
- 04最適化後の性能低下の確認
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ zhaono1/ agent-playbook --skill performance-engineerインストール後、Claude Code で/performance-engineerを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
README.mdreferences/checklist.mdmonitoring.mdoptimization.mdscripts/perf_report.pyprofile.py詳細
パフォーマンスエンジニア
アプリケーションのパフォーマンスを分析・最適化し、ボトルネックを特定して効率を改善する専門家です。
このスキルが有効になるとき
以下の場合に有効になります:
- パフォーマンスの問題を報告したとき
- パフォーマンスを最適化する必要があるとき
- 「遅い」や「レイテンシ」に言及したとき
- 効率を改善したいとき
パフォーマンス分析のプロセス
フェーズ 1:問題の特定
-
指標を定義する
- ベースラインはどのくらいですか?
- 目標はどのくらいですか?
- 許容範囲はどのくらいですか?
-
現在のパフォーマンスを測定する
# Response time curl -w "@curl-format.txt" -o /dev/null -s https://example.com/users # Database query time # Add timing logs to queries # Memory usage # Use profiler -
アプリケーションをプロファイリングする
# Node.js node --prof app.js # Python python -m cProfile app.py # Go go test -cpuprofile=cpu.prof
フェーズ 2:ボトルネックの特定
よくあるボトルネックの箇所:
| レイヤー | よくある問題 |
|---|---|
| データベース | N+1 クエリ、インデックスの欠如、大規模な結果セット |
| API | 過剰なデータ取得、キャッシュなし、直列リクエスト |
| アプリケーション | 非効率なアルゴリズム、過剰なログ出力 |
| フロントエンド | 大きなバンドル、再レンダリング、遅延読み込みなし |
| ネットワーク | リクエスト数の多さ、大きなペイロード、圧縮なし |
フェーズ 3:最適化
データベースの最適化
N+1 クエリ:
// Bad: N+1 queries
const users = await User.findAll();
for (const user of users) {
user.posts = await Post.findAll({ where: { userId: user.id } });
}
// Good: Eager loading
const users = await User.findAll({
include: [{ model: Post, as: 'posts' }]
});
インデックスの欠如:
-- Add index on frequently queried columns
CREATE INDEX idx_user_email ON users(email);
CREATE INDEX idx_post_user_id ON posts(user_id);
API の最適化
ページネーション:
// Always paginate large result sets
const users = await User.findAll({
limit: 100,
offset: page * 100
});
フィールド選択:
// Select only needed fields
const users = await User.findAll({
attributes: ['id', 'name', 'email']
});
圧縮:
// Enable gzip compression
app.use(compression());
フロントエンドの最適化
コード分割:
// Lazy load routes
const Dashboard = lazy(() => import('./Dashboard'));
メモ化:
// Use useMemo for expensive calculations
const filtered = useMemo(() =>
items.filter(item => item.active),
[items]
);
画像の最適化:
- WebP 形式を使用する
- 画像を遅延読み込みする
- レスポンシブ画像を使用する
- 画像を圧縮する
フェーズ 4:検証
- 再度測定する
- ベースラインと比較する
- デグレードがないことを確認する
- 改善内容を記録する
パフォーマンス目標
サービスの SLO、現在のベースライン、ワークロードの特性、コスト予算、重要なユーザージャーニーをもとに目標を設定してください。以下の表は出発点の一例にすぎません。根拠や担当者の合意がないまま、システムの受け入れ基準として示さないでください。
| 指標 | 目標 | 重大な閾値 |
|---|---|---|
| API 応答(p50) | < 100ms | < 500ms |
| API 応答(p95) | < 500ms | < 1s |
| API 応答(p99) | < 1s | < 2s |
| データベースクエリ | < 50ms | < 200ms |
| ページ読み込み(FMP) | < 2s | < 3s |
| インタラクティブになるまでの時間 | < 3s | < 5s |
| メモリ使用量 | < 512MB | < 1GB |
よくある最適化
キャッシュ戦略
// Cache expensive computations
const cache = new Map();
async function getUserStats(userId: string) {
if (cache.has(userId)) {
return cache.get(userId);
}
const stats = await calculateUserStats(userId);
cache.set(userId, stats);
// Invalidate after 5 minutes
setTimeout(() => cache.delete(userId), 5 * 60 * 1000);
return stats;
}
バッチ処理
// Bad: Individual requests
for (const id of userIds) {
await fetchUser(id);
}
// Good: Batch request
await fetchUsers(userIds);
デバウンス/スロットリング
// Debounce search input
const debouncedSearch = debounce(search, 300);
// Throttle scroll events
const throttledScroll = throttle(handleScroll, 100);
パフォーマンスの監視
主な指標
- 応答時間:リクエストの処理にかかる時間
- スループット:1 秒あたりのリクエスト数
- エラー率:失敗したリクエストの割合
- メモリ使用量:使用中のヒープ/RAM
- CPU 使用率:プロセッサーの使用率
監視ツール
| ツール | 用途 |
|---|---|
| Lighthouse | フロントエンドのパフォーマンス |
| New Relic | APM の監視 |
| Datadog | インフラストラクチャの監視 |
| Prometheus | 指標の収集 |
スクリプト
アプリケーションをプロファイリングする:
python3 scripts/profile.py --name <service-name> --output perf-profile.txt
パフォーマンスレポートを生成する:
python3 scripts/perf_report.py --name <service-name> --output perf-report.md
参考資料
references/optimization.md- 最適化手法references/monitoring.md- 監視の設定references/checklist.md- パフォーマンスチェックリスト
コメント
Markdown 対応