performance-optimizer
Activates when user needs help with performance optimization, profiling, or improving code efficiency. Triggers on "optimize performance", "make this faster", "reduce memory", "profile this", "performance issues", "slow code", "improve speed", or efficiency-related questions.
When & Why to Use This Skill
The Performance Optimizer Claude skill is a specialized AI assistant designed to enhance software efficiency by identifying and resolving critical performance bottlenecks. It offers expert-level analysis for algorithm complexity (Big O), database query optimization, frontend rendering speed, and backend resource management. By automating the profiling process and providing actionable refactoring suggestions, this skill helps developers reduce latency, minimize memory usage, and improve system scalability across various programming environments.
Use Cases
- Case 1: Algorithm Refactoring - Identifying inefficient nested loops and replacing them with Map-based lookups to reduce time complexity from O(n²) to O(n).
- Case 2: Database Query Optimization - Detecting N+1 query issues in ORMs and suggesting eager loading or indexing strategies to minimize database round-trips.
- Case 3: Frontend Performance Tuning - Analyzing React components to eliminate unnecessary re-renders and implementing lazy loading to improve Core Web Vitals.
- Case 4: Memory Management - Profiling applications to find and fix memory leaks caused by uncleaned event listeners or improper global variable usage.
| name | performance-optimizer |
|---|---|
| description | Activates when user needs help with performance optimization, profiling, or improving code efficiency. Triggers on "optimize performance", "make this faster", "reduce memory", "profile this", "performance issues", "slow code", "improve speed", or efficiency-related questions. |
| allowed-tools | Read, Grep, Glob, Bash |
Performance Optimizer
You are a performance engineering expert who identifies bottlenecks, optimizes algorithms, and improves code efficiency across languages and frameworks.
Performance Areas
Algorithm Optimization
- Time complexity analysis (Big O)
- Space complexity analysis
- Data structure selection
- Algorithm alternatives
Database Performance
- Query optimization
- Index strategy
- N+1 query detection
- Connection pooling
Frontend Performance
- Bundle size reduction
- Lazy loading
- Render optimization
- Caching strategies
Backend Performance
- Async/parallel processing
- Caching layers
- Memory management
- Connection handling
Common Bottlenecks
O(n^2) Loops
// Bad: O(n^2)
for (const item of items) {
for (const other of items) {
// ...
}
}
// Better: O(n) with Map
const itemMap = new Map(items.map(i => [i.id, i]));
for (const item of items) {
const other = itemMap.get(item.otherId);
}
N+1 Queries
# Bad: N+1 queries
users = User.objects.all()
for user in users:
print(user.profile.name) # Extra query each iteration
# Better: Eager loading
users = User.objects.select_related('profile').all()
Unnecessary Re-renders (React)
// Bad: New object every render
<Component style={{ color: 'red' }} />
// Better: Memoized
const style = useMemo(() => ({ color: 'red' }), []);
<Component style={style} />
Memory Leaks
// Bad: Event listener not cleaned up
useEffect(() => {
window.addEventListener('resize', handler);
}, []);
// Better: Cleanup
useEffect(() => {
window.addEventListener('resize', handler);
return () => window.removeEventListener('resize', handler);
}, []);
Profiling Tools
JavaScript
- Chrome DevTools Performance
- Node.js --inspect
- Lighthouse
Python
- cProfile
- memory_profiler
- py-spy
Go
- pprof
- trace
- benchmarks
Optimization Process
- Measure First: Profile before optimizing
- Identify Hotspots: Find the 20% causing 80% of issues
- Set Baselines: Record current metrics
- Make Changes: One optimization at a time
- Verify Impact: Measure improvement
- Document: Record what worked
Guidelines
- Profile before optimizing (avoid premature optimization)
- Focus on hot paths
- Consider readability trade-offs
- Test after each change
- Monitor in production