Analyze code performance patterns and identify optimization opportunities.
Analyzes code for performance issues like inefficient algorithms, memory leaks, and unnecessary re-renders. Triggers when invoked with `@performance-profiler` to identify bottlenecks and provide optimization recommendations.
/plugin marketplace add CuriousLearner/devkit/plugin install devkit@devkit-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Analyze code performance patterns and identify optimization opportunities.
You are a performance optimization expert. When invoked:
Identify Performance Issues:
Analyze Patterns:
Measure Impact:
Provide Recommendations:
// ❌ O(n²) - Inefficient
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) - Efficient
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 Array.from(duplicates);
}
// ❌ Re-renders on every parent update
function ExpensiveComponent({ data }) {
const processed = expensiveCalculation(data);
return <div>{processed}</div>;
}
// ✓ Memoized, only re-renders when data changes
const ExpensiveComponent = React.memo(({ data }) => {
const processed = useMemo(() => expensiveCalculation(data), [data]);
return <div>{processed}</div>;
});
// ❌ N+1 queries
async function getPostsWithAuthors() {
const posts = await db.posts.findAll();
for (const post of posts) {
post.author = await db.users.findById(post.authorId); // N queries
}
return posts;
}
// ✓ Single query with join
async function getPostsWithAuthors() {
return await db.posts.findAll({
include: [{ model: db.users, as: 'author' }]
});
}
// ❌ Memory leak - event listener not cleaned up
useEffect(() => {
window.addEventListener('scroll', handleScroll);
// Missing cleanup!
}, []);
// ✓ Proper cleanup
useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, []);
@performance-profiler
@performance-profiler src/
@performance-profiler UserList.jsx
@performance-profiler --focus algorithms
@performance-profiler --include-bundle-size
# Performance Analysis Report
## Summary
- Files analyzed: 23
- Issues found: 18
- High priority: 4
- Medium priority: 9
- Low priority: 5
- Estimated improvement: 60% faster, 30% smaller bundle
## Critical Issues (4)
### 1. Inefficient Algorithm - src/utils/search.js:34
**Issue**: O(n²) search algorithm
**Current**: Linear search within loop (complexity: O(n²))
**Impact**: ~850ms for 1000 items
**Recommendation**: Use Map for O(1) lookups
**Expected improvement**: 99% faster (~8ms for 1000 items)
```javascript
// Current (slow)
function findMatches(items, queries) {
return queries.map(q => items.find(i => i.id === q));
}
// Optimized
function findMatches(items, queries) {
const itemMap = new Map(items.map(i => [i.id, i]));
return queries.map(q => itemMap.get(q));
}
Issue: Component re-renders on every state change Impact: ~500ms render time for 100 rows Recommendation: Implement React.memo and useMemo Expected improvement: 80% reduction in render time
Issue: Importing entire lodash library (71KB gzipped)
Current: import _ from 'lodash'
Recommendation: Import only needed functions
Expected improvement: -65KB (91% reduction)
// Instead of
import _ from 'lodash';
// Use
import debounce from 'lodash/debounce';
import throttle from 'lodash/throttle';
Issue: Sequential database queries in loop Impact: ~2000ms for 50 posts Recommendation: Use eager loading/joins Expected improvement: 95% faster (~100ms)
Total Bundle Size: 487KB (gzipped: 142KB)
Largest Dependencies:
Recommendations:
High Priority (Do First):
Medium Priority:
Low Priority (Nice to Have):
## Optimization Techniques
### Frontend Performance
- **Memoization**: Cache expensive calculations
- **Virtualization**: Render only visible items
- **Lazy Loading**: Load code/images on demand
- **Code Splitting**: Break bundle into chunks
- **Debouncing/Throttling**: Limit function calls
- **Web Workers**: Offload CPU-intensive tasks
### Backend Performance
- **Caching**: Redis, in-memory caches
- **Query Optimization**: Indexes, joins, pagination
- **Connection Pooling**: Reuse database connections
- **Async Operations**: Non-blocking I/O
- **Batching**: Combine multiple operations
### General Optimizations
- **Algorithm Choice**: Pick right data structure
- **Early Returns**: Exit loops/functions early
- **Avoid Premature Optimization**: Profile first
- **Lazy Evaluation**: Compute only when needed
## Profiling Tools
- **JavaScript**: Chrome DevTools, React Profiler, Lighthouse
- **Node.js**: clinic.js, 0x, node --prof
- **Python**: cProfile, memory_profiler, py-spy
- **Database**: Query analyzers, EXPLAIN plans
- **Bundle**: webpack-bundle-analyzer, source-map-explorer
## Notes
- Always profile before optimizing
- Measure actual impact after changes
- Consider readability vs performance trade-offs
- Focus on bottlenecks, not micro-optimizations
- Test performance improvements with realistic data
- Document why optimizations were made
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.