| name | performance-hunter |
| description | Find and fix performance bottlenecks in ANY language or framework. Use when applications are slow, memory usage is high, or you need to optimize critical paths. |
Performance Hunter - Universal Speed Optimization
🎯 When to Use This Skill
Use when experiencing:
- Slow page loads
- High CPU/memory usage
- Sluggish UI responses
- Database timeouts
- API latency issues
- "It used to be faster"
⚡ Quick Wins (80/20 Rule)
The Big 5 Performance Killers (Check These First):
- N+1 Queries - Multiple DB calls in loops
- Missing Indexes - Unindexed database queries
- Large Bundles - Unoptimized assets/dependencies
- Memory Leaks - Unreleased references
- Blocking I/O - Synchronous operations
🔍 Step 1: MEASURE (Don't Guess!)
WITH MCP Tools:
"Profile the performance of [feature/endpoint/page]"
"Find performance bottlenecks in my application"
WITHOUT MCP:
Quick Measurements:
time curl http://localhost:3000/api/endpoint
for i in {1..10}; do time curl -s http://localhost:3000 > /dev/null; done
console.time('query');
// your database query
console.timeEnd('query');
Browser Performance (Frontend):
performance.mark('myFeature-start');
performance.mark('myFeature-end');
performance.measure('myFeature', 'myFeature-start', 'myFeature-end');
performance.getEntriesByType('measure');
🎯 Step 2: PROFILE (Find Bottlenecks)
Universal Profiling by Language:
JavaScript/Node.js:
node --inspect app.js
console.time('operation');
// code
console.timeEnd('operation');
Python:
import cProfile
import pstats
cProfile.run('your_function()', 'profile_stats')
stats = pstats.Stats('profile_stats')
stats.sort_stats('cumulative').print_stats(10)
Java:
jstack <pid>
jmap -histo <pid>
Go:
import _ "net/http/pprof"
Database Profiling:
EXPLAIN ANALYZE SELECT ...;
SET profiling = 1;
SHOW PROFILES;
SHOW PROFILE FOR QUERY 1;
db.collection.find().explain("executionStats")
🔧 Step 3: OPTIMIZE (Fix Bottlenecks)
1. Database Optimization
WITH MCP (DB Schema Designer):
"Optimize my database queries for performance"
WITHOUT MCP:
N+1 Query Fix:
const users = await getUsers();
for (const user of users) {
user.posts = await getPostsByUserId(user.id);
}
const usersWithPosts = await getUsersWithPosts();
Add Indexes:
SELECT query, calls, mean_time
FROM pg_stat_statements
ORDER BY mean_time DESC;
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_posts_user_created ON posts(user_id, created_at);
2. Frontend Optimization
Bundle Size:
npm run build -- --stats
webpack-bundle-analyzer stats.json
React/Vue Specific:
const ExpensiveComponent = React.memo(({ data }) => {
});
import { FixedSizeList } from 'react-window';
3. Backend Optimization
Caching Strategy:
const cache = new Map();
async function getExpensiveData(key) {
if (cache.has(key)) {
return cache.get(key);
}
const data = await expensive_operation();
cache.set(key, data);
setTimeout(() => cache.delete(key), 60000);
return data;
}
Async/Parallel Processing:
for (const item of items) {
await processItem(item);
}
const pLimit = require('p-limit');
const limit = pLimit(5);
await Promise.all(items.map(item => limit(() => processItem(item))));
4. Memory Optimization
Find Memory Leaks:
if (global.gc) {
global.gc();
const used = process.memoryUsage();
console.log('Memory:', Math.round(used.heapUsed / 1024 / 1024), 'MB');
}
Fix Common Leaks:
componentWillUnmount() {
window.removeEventListener('resize', this.handler);
}
const timer = setTimeout(...);
clearTimeout(timer);
const cache = new WeakMap();
📊 Performance Monitoring
Quick Monitoring Setup:
function monitor(fn, name, threshold = 100) {
return async (...args) => {
const start = Date.now();
const result = await fn(...args);
const duration = Date.now() - start;
if (duration > threshold) {
console.warn(`⚠️ Slow operation: ${name} took ${duration}ms`);
}
return result;
};
}
const fastQuery = monitor(slowQuery, 'UserQuery', 50);
🚀 Quick Performance Checklist
Frontend:
Backend:
Database:
💡 Language-Specific Quick Wins
Node.js:
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
cluster.fork();
}
}
Python:
from functools import lru_cache
@lru_cache(maxsize=128)
def expensive_function(param):
return complex_calculation(param)
Java:
StringBuilder sb = new StringBuilder();
for (String s : strings) {
sb.append(s);
}
🎯 Performance Goals by Type
Web Application:
- Page load: < 3 seconds
- API calls: < 500ms
- Search: < 200ms
- Form submit: < 1 second
Mobile App:
- Launch: < 2 seconds
- Screen transition: < 300ms
- List scroll: 60 FPS
- Network retry: Exponential backoff
API Service:
- p50 latency: < 50ms
- p95 latency: < 200ms
- p99 latency: < 1 second
- Error rate: < 0.1%
📈 Before/After Metrics Template
## Performance Optimization Report
### Metric | Before | After | Improvement
---------|---------|--------|-------------
Page Load | 4.2s | 1.8s | -57%
API Response | 800ms | 180ms | -77%
Memory Usage | 512MB | 320MB | -37%
Bundle Size | 1.2MB | 420KB | -65%
### Changes Made:
1. Added database indexes
2. Implemented caching layer
3. Enabled gzip compression
4. Lazy loaded images
5. Code split routes
Remember: Measure → Profile → Optimize → Verify! 🚀