analyze-performance
БесплатноБез исполняемых скриптовНе проверенパフォーマンスボトルネックを特定し、最適化提案を提示
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
civicship-api パフォーマンス分析
パフォーマンスのボトルネックを特定し、最適化提案を提示します。N+1問題、不要なクエリ、非効率なアルゴリズムを検出します。
使用方法
# ドメイン全体のパフォーマンス分析
/analyze-performance wallet
# 特定ファイルの分析
/analyze-performance src/application/domain/account/wallet/service.ts
# 全体のパフォーマンスレポート
/analyze-performance --all
引数:
$ARGUMENTS: ドメイン名、ファイルパス、または--all
パフォーマンス分析プロセス
ステップ1: N+1問題の検出
ループ内のクエリ実行を検出:
# ループ内のawait検索
grep -A 5 "for.*of\|for.*in\|forEach\|map" src/application/domain/${DOMAIN}/**/*.ts | grep -B 3 "await.*find\|await.*query"
# DataLoaderの使用確認
grep -r "ctx.loaders" src/application/domain/${DOMAIN}/**/*.ts
N+1問題レポート:
## N+1問題の検出
### 🔴 Critical: N+1問題あり
#### 問題1: UserResolver.wallets
**ファイル:** `src/application/domain/account/user/controller/resolver.ts:45`
**コード:**
\`\`\`typescript
User: {
wallets: async (parent, _, ctx) => {
// 全ユーザーに対してこのクエリが実行される(N+1)
return await prisma.t_wallets.findMany({
where: { userId: parent.id }
});
}
}
\`\`\`
**問題:**
- 100ユーザーを取得すると、100回のクエリが実行される
- レスポンスタイム: 5秒以上
**推奨修正:**
\`\`\`typescript
User: {
wallets: (parent, _, ctx) => {
// DataLoaderでバッチローディング
return ctx.loaders.walletsByUserId.load(parent.id);
}
}
// DataLoader定義
const walletsByUserIdLoader = new DataLoader(async (userIds) => {
const wallets = await prisma.t_wallets.findMany({
where: { userId: { in: userIds } }
});
// userIdごとにグループ化して返す
return userIds.map(id => wallets.filter(w => w.userId === id));
});
\`\`\`
**効果:**
- クエリ数: 100回 → 1回
- レスポンスタイム: 5秒 → 50ms(100倍改善)
---
### ✅ 正しい実装例
#### Opportunity.community(DataLoader使用)
**ファイル:** `src/application/domain/experience/opportunity/controller/resolver.ts:30`
\`\`\`typescript
Opportunity: {
community: (parent, _, ctx) => {
return ctx.loaders.community.load(parent.communityId);
}
}
\`\`\`
**評価:** N+1問題なし
ステップ2: 不要なクエリの検出
同じデータを複数回取得している箇所を検出:
# 同じクエリが複数回実行されている可能性
grep -A 3 "findUnique\|findFirst" src/application/domain/${DOMAIN}/**/*.ts | sort | uniq -c | sort -rn
不要クエリレポート:
## 不要なクエリ
### 問題1: 重複したウォレット取得
**ファイル:** `src/application/domain/transaction/point-transfer/service.ts:120`
**コード:**
\`\`\`typescript
async transferPoints(ctx, input, tx) {
// ウォレットを2回取得(無駄)
const fromWallet = await this.walletRepo.findById(ctx, input.fromWalletId, tx);
const toWallet = await this.walletRepo.findById(ctx, input.toWalletId, tx);
// バリデーション後、再度取得(無駄)
const fromWalletAgain = await this.walletRepo.findById(ctx, input.fromWalletId, tx);
// ...
}
\`\`\`
**推奨修正:**
\`\`\`typescript
async transferPoints(ctx, input, tx) {
// 1回だけ取得
const [fromWallet, toWallet] = await Promise.all([
this.walletRepo.findById(ctx, input.fromWalletId, tx),
this.walletRepo.findById(ctx, input.toWalletId, tx)
]);
// 再取得せず、メモリ上のデータを使用
// ...
}
\`\`\`
**効果:**
- クエリ数: 3回 → 2回
- レスポンスタイム: 15ms → 10ms
ステップ3: SELECT句の最適化
必要以上のカラムを取得している箇所を検出:
# SELECT * の使用箇所
grep -r "prisma.*\.findMany\|prisma.*\.findUnique" src/application/domain/${DOMAIN}/**/*.ts | grep -v "select:"
SELECT最適化レポート:
## SELECT句の最適化
### 問題1: 全カラム取得
**ファイル:** `src/application/domain/account/wallet/data/repository.ts:50`
**コード:**
\`\`\`typescript
async findById(ctx, id, tx) {
// 全カラムを取得(無駄が多い)
return tx.t_wallets.findUnique({ where: { id } });
}
\`\`\`
**問題:**
- 不要なカラム(例: `metadata`, `internalNotes`)も取得
- ネットワーク転送量が増加
- メモリ使用量が増加
**推奨修正:**
\`\`\`typescript
async findById(ctx, id, tx) {
// 必要なカラムのみ取得
return tx.t_wallets.findUnique({
where: { id },
select: {
id: true,
userId: true,
balance: true,
expiresAt: true,
createdAt: true,
updatedAt: true
}
});
}
\`\`\`
**効果:**
- データ転送量: 1KB → 200B(80%削減)
- メモリ使用量: 削減
ステップ4: インデックスの確認
データベースインデックスの不足を検出:
# WHERE句で使用されているカラムを抽出
grep -r "where:" src/application/domain/${DOMAIN}/data/repository.ts | grep -o "{.*}" | sort | uniq
# Prismaスキーマのインデックス確認
grep -A 10 "model t_wallets" prisma/schema.prisma | grep "@@index"
インデックスレポート:
## インデックス分析
### 推奨: インデックス追加
#### インデックス1: t_wallets.expiresAt
**使用箇所:**
- バッチ処理: 有効期限切れポイントの検索
- クエリ: `WHERE expiresAt < NOW()`
**現状:** インデックスなし
**推奨:**
\`\`\`prisma
model t_wallets {
// ...
@@index([expiresAt])
}
\`\`\`
**効果:**
- クエリ時間: 500ms → 10ms(50倍改善)
---
#### インデックス2: t_wallets.userId + createdAt
**使用箇所:**
- ウォレット一覧の取得(ユーザーID + 作成日でソート)
**現状:** userId のみインデックス
**推奨:**
\`\`\`prisma
model t_wallets {
// ...
@@index([userId, createdAt])
}
\`\`\`
**効果:**
- ソートパフォーマンス向上
ステップ5: 非効率なアルゴリズムの検出
計算量が大きいコードを検出:
## アルゴリズム分析
### 問題1: ネストループ(O(N²))
**ファイル:** `src/application/domain/reward/utility/service.ts:80`
**コード:**
\`\`\`typescript
async findMatchingUtilities(ctx, userId) {
const utilities = await this.repo.findAll(ctx); // 1,000件
const userSkills = await this.userSkillRepo.findByUserId(ctx, userId); // 10件
Установить analyze-performance в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobBashВложенные файлы
FAQ
Что делает скилл analyze-performance?
パフォーマンスボトルネックを特定し、最適化提案を提示
Как установить скилл analyze-performance?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл analyze-performance запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic