| name | performance-profiler |
| description | Profile and optimize application performance including load times, memory usage, and rendering. Use when debugging slow performance, memory leaks, or optimizing app speed. |
Performance Profiler
Instructions
When profiling performance:
- Identify the bottleneck type: Network, rendering, memory, or compute
- Measure baseline before optimizing
- Profile with appropriate tools
- Apply optimizations
- Measure improvement
Web Performance
Core Web Vitals
npx lighthouse https://yoursite.com --view
npx lighthouse https://yoursite.com --only-categories=performance
Target Metrics:
| Metric | Good | Needs Work | Poor |
|---|
| LCP (Largest Contentful Paint) | < 2.5s | 2.5-4s | > 4s |
| INP (Interaction to Next Paint) | < 200ms | 200-500ms | > 500ms |
| CLS (Cumulative Layout Shift) | < 0.1 | 0.1-0.25 | > 0.25 |
Bundle Analysis
ANALYZE=true npm run build
npx webpack-bundle-analyzer stats.json
npx vite-bundle-visualizer
React Performance
React DevTools Profiler
- Install React DevTools browser extension
- Open DevTools → Profiler tab
- Click Record, interact with app, stop recording
- Analyze flame graph for slow components
Common React Optimizations
const MemoizedList = React.memo(function List({ items }) {
return items.map(item => <Item key={item.id} {...item} />);
});
const sortedItems = useMemo(() => {
return [...items].sort((a, b) => a.name.localeCompare(b.name));
}, [items]);
const handleClick = useCallback((id: string) => {
setSelected(id);
}, []);
import { FixedSizeList } from 'react-window';
function VirtualList({ items }) {
return (
<FixedSizeList
height={400}
itemCount={items.length}
=
=
>
{({ index, style }) => (
{items[index].name}
)}
);
}
= .( ());
() {
(
);
}
Node.js Performance
Profiling
node --prof app.js
node --prof-process isolate-*.log > profile.txt
node --inspect app.js
npx clinic doctor -- node app.js
npx clinic flame -- node app.js
npx clinic bubbleprof -- node app.js
Memory Leak Detection
const used = process.memoryUsage();
console.log({
heapUsed: `${Math.round(used.heapUsed / 1024 / 1024)} MB`,
heapTotal: `${Math.round(used.heapTotal / 1024 / 1024)} MB`,
external: `${Math.round(used.external / 1024 / 1024)} MB`,
});
Database Performance
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
SELECT relname, seq_scan, idx_scan
FROM pg_stat_user_tables
WHERE seq_scan > idx_scan;
Query Optimization
const users = await db.user.findMany();
for (const user of users) {
const posts = await db.post.findMany({ where: { userId: user.id } });
}
const users = await db.user.findMany({
include: { posts: true }
});
const users = await db.user.findMany({
select: { id: true, name: true, email: true }
});
Quick Wins Checklist