Performance Optimization Skill
Use this skill when optimizing application performance, reducing load times, or improving responsiveness.
Overview
Systematic approach to identifying and fixing performance bottlenecks in web applications.
When to Use
Use this skill when:
- Application is slow
- Bundle size is large
- Page load times are high
- User reports lag
- Need to improve Core Web Vitals
Workflow
Step 1: Measure and Profile
- Identify performance metrics
- Use profiling tools
- Measure baseline performance
- Identify bottlenecks
Metrics to Track:
- First Contentful Paint (FCP)
- Largest Contentful Paint (LCP)
- Time to Interactive (TTI)
- Total Blocking Time (TBT)
- Cumulative Layout Shift (CLS)
- Bundle size
- Network requests
Tools:
- Chrome DevTools Performance tab
- Lighthouse
- WebPageTest
- Bundle analyzers (webpack-bundle-analyzer)
Step 2: Optimize Bundle Size
- Analyze bundle composition
- Remove unused code
- Code splitting
- Tree shaking
- Minification
Strategies:
- Dynamic imports for routes
- Lazy load components
- Remove unused dependencies
- Use smaller alternatives
- Optimize images
Checklist:
- Bundle size analyzed
- Unused code removed
- Code splitting implemented
- Tree shaking working
- Minification enabled
Step 3: Optimize Images
- Use appropriate formats (WebP, AVIF)
- Compress images
- Lazy load images
- Use responsive images
- Provide image dimensions
Strategies:
- Convert to WebP/AVIF
- Use
loading="lazy" - Use
srcsetfor responsive - Provide width/height to prevent CLS
- Use CDN for images
Step 4: Optimize Rendering
- Reduce re-renders
- Use React.memo / useMemo / useCallback
- Virtualize long lists
- Optimize CSS
- Reduce layout shifts
React Optimizations:
- Memoize expensive computations with
useMemo - Memoize callbacks with
useCallback - Memoize components with
React.memo - Virtualize lists (react-window, react-virtualized)
- Code split routes
Step 5: Optimize Network
- Enable compression (gzip/brotli)
- Use HTTP/2
- Implement caching
- Reduce requests
- Use CDN
Strategies:
- Enable gzip/brotli compression
- Set cache headers
- Use service workers
- Combine requests
- Use CDN for static assets
Step 6: Optimize JavaScript
- Defer non-critical JS
- Remove unused code
- Minimize main thread work
- Use web workers for heavy tasks
- Optimize loops and algorithms
Performance Budget
Set targets:
- Bundle size: < 200KB (gzipped)
- LCP: < 2.5s
- FCP: < 1.8s
- TTI: < 3.8s
- CLS: < 0.1
Anti-Patterns
❌ Don't do:
- Loading everything upfront
- Not using code splitting
- Large bundle sizes
- Unoptimized images
- Blocking main thread
- No caching strategy
✅ Do instead:
- Lazy load routes and components
- Use code splitting
- Keep bundles small
- Optimize images (WebP, lazy loading)
- Defer non-critical JS
- Implement caching strategy
Common Optimizations
Code Splitting
// Route-based
const Dashboard = lazy(() => import('./Dashboard'));
const Settings = lazy(() => import('./Settings'));
// Component-based
const HeavyComponent = lazy(() => import('./HeavyComponent'));
Memoization
// useMemo for expensive computations
const processedData = useMemo(() => {
return expensiveOperation(data);
}, [data]);
// useCallback for callbacks
const handleClick = useCallback(() => {
handleItem(item);
}, [handleItem, item]);
// React.memo for components
export default React.memo(Component);
Virtual Lists
import { FixedSizeList } from 'react-window';
<FixedSizeList
height={600}
itemCount={1000}
itemSize={50}
>
{({ index, style }) => (
<div style={style}>Row {index}</div>
)}
</FixedSizeList>
Verification
- Lighthouse score > 90
- Bundle size within budget
- Images optimized
- No performance regressions
- Metrics meet targets
Related Skills
- API Design - Optimize API calls
- Component Design - Optimize rendering
- Database Design - Optimize queries
Related Commands
- Test Command - Run performance tests
- Build Command - Measure build size
Next Steps
- Lighthouse audit - Run performance audit
- Bundle Analyzer - Analyze bundle