optimizing-performance
Analyzes and optimizes application performance across frontend, backend, and database layers. Use when diagnosing slowness, improving load times, optimizing queries, reducing bundle size, or when asked about performance issues.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o optimizing-performance.zip https://jpskill.com/download/17946.zip && unzip -o optimizing-performance.zip && rm optimizing-performance.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17946.zip -OutFile "$d\optimizing-performance.zip"; Expand-Archive "$d\optimizing-performance.zip" -DestinationPath $d -Force; ri "$d\optimizing-performance.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
optimizing-performance.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
optimizing-performanceフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
パフォーマンスの最適化
パフォーマンス最適化のワークフロー
このチェックリストをコピーして、進捗状況を追跡してください。
パフォーマンス最適化の進捗状況:
- [ ] ステップ 1: ベースラインパフォーマンスの測定
- [ ] ステップ 2: ボトルネックの特定
- [ ] ステップ 3: ターゲットを絞った最適化の適用
- [ ] ステップ 4: 再度測定して比較
- [ ] ステップ 5: 目標が達成されない場合は繰り返す
重要なルール: データなしで最適化しないでください。変更前と変更後には必ずプロファイルしてください。
ステップ 1: ベースラインの測定
プロファイリングコマンド
# Node.js のプロファイリング
node --prof app.js
node --prof-process isolate*.log > profile.txt
# Python のプロファイリング
python -m cProfile -o profile.stats app.py
python -m pstats profile.stats
# Web パフォーマンス
lighthouse https://example.com --output=json
ステップ 2: ボトルネックの特定
一般的なボトルネックのカテゴリ
| カテゴリ | 症状 | ツール |
|---|---|---|
| CPU | CPU 使用率が高い、計算が遅い | プロファイラー、 flame graphs |
| メモリ | RAM が多い、 GC ポーズ、 OOM | ヒープスナップショット、メモリプロファイラー |
| I/O | ディスク/ネットワークが遅い、待機 | strace, ネットワークインスペクター |
| データベース | クエリが遅い、ロック競合 | クエリ アナライザー, EXPLAIN |
ステップ 3: 最適化の適用
フロントエンドの最適化
Bundle Size:
// ❌ ライブラリ全体をインポート
import _ from 'lodash';
// ✅ 必要な関数のみをインポート
import debounce from 'lodash/debounce';
// ✅ コード分割にダイナミックインポートを使用
const HeavyComponent = lazy(() => import('./HeavyComponent'));
Rendering:
// ❌ 親の更新ごとにレンダリング
function Child({ data }) {
return <ExpensiveComponent data={data} />;
}
// ✅ props が変更されない場合はメモ化
const Child = memo(function Child({ data }) {
return <ExpensiveComponent data={data} />;
});
// ✅ 高コストな計算には useMemo を使用
const processed = useMemo(() => expensiveCalc(data), [data]);
Images:
<!-- ❌ 最適化されていない -->
<img src="large-image.jpg" />
<!-- ✅ 最適化されている -->
<img
src="image.webp"
srcset="image-300.webp 300w, image-600.webp 600w"
sizes="(max-width: 600px) 300px, 600px"
loading="lazy"
decoding="async"
/>
バックエンドの最適化
Database Queries:
-- ❌ N+1 クエリ問題
SELECT * FROM users;
-- 次に、各ユーザーに対して:
SELECT * FROM orders WHERE user_id = ?;
-- ✅ JOIN を使用した単一のクエリ
SELECT u.*, o.*
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;
-- ✅ またはページネーションを使用
SELECT * FROM users LIMIT 100 OFFSET 0;
Caching Strategy:
// 多層キャッシュ
const getUser = async (id) => {
// L1: インメモリキャッシュ (最速)
let user = memoryCache.get(`user:${id}`);
if (user) return user;
// L2: Redis キャッシュ (高速)
user = await redis.get(`user:${id}`);
if (user) {
memoryCache.set(`user:${id}`, user, 60);
return JSON.parse(user);
}
// L3: データベース (低速)
user = await db.users.findById(id);
await redis.setex(`user:${id}`, 3600, JSON.stringify(user));
memoryCache.set(`user:${id}`, user, 60);
return user;
};
Async Processing:
// ❌ ブロッキング操作
app.post('/upload', async (req, res) => {
await processVideo(req.file); // 5 分かかる
res.send('Done');
});
// ✅ バックグラウンド処理用のキュー
app.post('/upload', async (req, res) => {
const jobId = await queue.add('processVideo', { file: req.file });
res.send({ jobId, status: 'processing' });
});
アルゴリズムの最適化
// ❌ O(n²) - ネストされたループ
function findDuplicates(arr) {
const duplicates = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) duplicates.push(arr[i]);
}
}
return duplicates;
}
// ✅ O(n) - ハッシュマップ
function findDuplicates(arr) {
const seen = new Set();
const duplicates = new Set();
for (const item of arr) {
if (seen.has(item)) duplicates.add(item);
seen.add(item);
}
return [...duplicates];
}
ステップ 4: 再度測定
最適化を適用した後、プロファイリングを再実行して比較します。
比較チェックリスト:
- [ ] ベースラインと同じプロファイリングツールを実行
- [ ] 変更前と変更後のメトリクスを比較
- [ ] 他の領域でリグレッションがないことを確認
- [ ] 改善率を文書化
パフォーマンス目標
Web Vitals
| メトリクス | 良好 | 要改善 | 不良 |
|---|---|---|---|
| LCP | < 2.5s | 2.5-4s | > 4s |
| FID | < 100ms | 100-300ms | > 300ms |
| CLS | < 0.1 | 0.1-0.25 | > 0.25 |
| TTFB | < 800ms | 800ms-1.8s | > 1.8s |
API Performance
| メトリクス | 目標 |
|---|---|
| P50 Latency | < 100ms |
| P95 Latency | < 500ms |
| P99 Latency | < 1s |
| Error Rate | < 0.1% |
バリデーション
最適化後、結果を検証します。
パフォーマンスの検証:
- [ ] ベースラインからメトリクスが改善された
- [ ] 機能のリグレッションがない
- [ ] 新しいエラーが発生していない
- [ ] 変更が持続可能である (一時的な修正ではない)
- [ ] パフォーマンスの向上が文書化されている
目標が達成されない場合は、ステップ 2 に戻り、残りのボトルネックを特定します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Optimizing Performance
Performance Optimization Workflow
Copy this checklist and track progress:
Performance Optimization Progress:
- [ ] Step 1: Measure baseline performance
- [ ] Step 2: Identify bottlenecks
- [ ] Step 3: Apply targeted optimizations
- [ ] Step 4: Measure again and compare
- [ ] Step 5: Repeat if targets not met
Critical Rule: Never optimize without data. Always profile before and after changes.
Step 1: Measure Baseline
Profiling Commands
# Node.js profiling
node --prof app.js
node --prof-process isolate*.log > profile.txt
# Python profiling
python -m cProfile -o profile.stats app.py
python -m pstats profile.stats
# Web performance
lighthouse https://example.com --output=json
Step 2: Identify Bottlenecks
Common Bottleneck Categories
| Category | Symptoms | Tools |
|---|---|---|
| CPU | High CPU usage, slow computation | Profiler, flame graphs |
| Memory | High RAM, GC pauses, OOM | Heap snapshots, memory profiler |
| I/O | Slow disk/network, waiting | strace, network inspector |
| Database | Slow queries, lock contention | Query analyzer, EXPLAIN |
Step 3: Apply Optimizations
Frontend Optimizations
Bundle Size:
// ❌ Import entire library
import _ from 'lodash';
// ✅ Import only needed functions
import debounce from 'lodash/debounce';
// ✅ Use dynamic imports for code splitting
const HeavyComponent = lazy(() => import('./HeavyComponent'));
Rendering:
// ❌ Render on every parent update
function Child({ data }) {
return <ExpensiveComponent data={data} />;
}
// ✅ Memoize when props don't change
const Child = memo(function Child({ data }) {
return <ExpensiveComponent data={data} />;
});
// ✅ Use useMemo for expensive computations
const processed = useMemo(() => expensiveCalc(data), [data]);
Images:
<!-- ❌ Unoptimized -->
<img src="large-image.jpg" />
<!-- ✅ Optimized -->
<img
src="image.webp"
srcset="image-300.webp 300w, image-600.webp 600w"
sizes="(max-width: 600px) 300px, 600px"
loading="lazy"
decoding="async"
/>
Backend Optimizations
Database Queries:
-- ❌ N+1 Query Problem
SELECT * FROM users;
-- Then for each user:
SELECT * FROM orders WHERE user_id = ?;
-- ✅ Single query with JOIN
SELECT u.*, o.*
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;
-- ✅ Or use pagination
SELECT * FROM users LIMIT 100 OFFSET 0;
Caching Strategy:
// Multi-layer caching
const getUser = async (id) => {
// L1: In-memory cache (fastest)
let user = memoryCache.get(`user:${id}`);
if (user) return user;
// L2: Redis cache (fast)
user = await redis.get(`user:${id}`);
if (user) {
memoryCache.set(`user:${id}`, user, 60);
return JSON.parse(user);
}
// L3: Database (slow)
user = await db.users.findById(id);
await redis.setex(`user:${id}`, 3600, JSON.stringify(user));
memoryCache.set(`user:${id}`, user, 60);
return user;
};
Async Processing:
// ❌ Blocking operation
app.post('/upload', async (req, res) => {
await processVideo(req.file); // Takes 5 minutes
res.send('Done');
});
// ✅ Queue for background processing
app.post('/upload', async (req, res) => {
const jobId = await queue.add('processVideo', { file: req.file });
res.send({ jobId, status: 'processing' });
});
Algorithm Optimizations
// ❌ O(n²) - nested loops
function findDuplicates(arr) {
const duplicates = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i] === arr[j]) duplicates.push(arr[i]);
}
}
return duplicates;
}
// ✅ O(n) - hash map
function findDuplicates(arr) {
const seen = new Set();
const duplicates = new Set();
for (const item of arr) {
if (seen.has(item)) duplicates.add(item);
seen.add(item);
}
return [...duplicates];
}
Step 4: Measure Again
After applying optimizations, re-run profiling and compare:
Comparison Checklist:
- [ ] Run same profiling tools as baseline
- [ ] Compare metrics before vs after
- [ ] Verify no regressions in other areas
- [ ] Document improvement percentages
Performance Targets
Web Vitals
| Metric | Good | Needs Work | Poor |
|---|---|---|---|
| LCP | < 2.5s | 2.5-4s | > 4s |
| FID | < 100ms | 100-300ms | > 300ms |
| CLS | < 0.1 | 0.1-0.25 | > 0.25 |
| TTFB | < 800ms | 800ms-1.8s | > 1.8s |
API Performance
| Metric | Target |
|---|---|
| P50 Latency | < 100ms |
| P95 Latency | < 500ms |
| P99 Latency | < 1s |
| Error Rate | < 0.1% |
Validation
After optimization, validate results:
Performance Validation:
- [ ] Metrics improved from baseline
- [ ] No functionality regressions
- [ ] No new errors introduced
- [ ] Changes are sustainable (not one-time fixes)
- [ ] Performance gains documented
If targets not met, return to Step 2 and identify remaining bottlenecks.