performance-optimization
npx machina-cli add skill JanSzewczyk/claude-plugins/performance-optimization --openclawPerformance Optimization Skill
Performance optimization patterns for Next.js applications.
Reference Files:
- bundle-analysis.md - Bundle size optimization
- react-rendering.md - React performance patterns
- database-optimization.md - Query optimization
- examples.md - Practical examples
Performance Philosophy
Principles:
- Measure first - Never optimize without metrics
- Target bottlenecks - Focus on the biggest impact areas
- User-centric - Prioritize perceived performance
- Iterative - Small, measurable improvements
Quick Reference
Bundle Size
# Analyze bundle
npm run analyze
# Targets
# - Total: < 200KB gzipped (first load)
# - Per-route: < 100KB gzipped
Quick Wins:
// Dynamic imports for heavy components
const Chart = dynamic(() => import("./Chart"), { ssr: false });
// Prefer native implementations
const debounce = (fn: Function, ms: number) => {
// ✅ Native
let timeout: NodeJS.Timeout;
return (...args: unknown[]) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), ms);
};
};
React Rendering
// With React Compiler - usually automatic optimization
// Manual memoization only for:
// 1. External library callbacks
const stableHandler = useCallback(() => {}, []);
// 2. Context values
const value = useMemo(() => ({ state, dispatch }), [state]);
// 3. Virtualized lists (50+ items)
import { useVirtualizer } from "@tanstack/react-virtual";
Database Queries
// Always use limits
const query = db.collection("items").where("userId", "==", userId).limit(20);
// Parallel fetching
const [users, posts] = await Promise.all([getUsers(), getPosts()]);
Core Web Vitals
| Metric | Target | Optimization |
|---|---|---|
| LCP | < 2.5s | priority on hero image, preload fonts |
| INP | < 200ms | startTransition, defer non-critical JS |
| CLS | < 0.1 | Fixed dimensions, skeleton loaders |
Performance Targets
Bundle Size Targets
| Category | Target (gzipped) |
|---|---|
| First Load JS | < 100KB |
| Per-page JS | < 50KB |
| Total app | < 300KB |
| Single dependency | < 30KB |
Runtime Targets
| Metric | Good | Needs Work |
|---|---|---|
| Time to Interactive | < 3s | > 5s |
| First Contentful Paint | < 1.8s | > 3s |
| Server Response | < 200ms | > 500ms |
| Database Query | < 100ms | > 500ms |
Analysis Commands
# Bundle analysis
npm run analyze
# Build output
npm run build
# Check .next/static/chunks sizes
# Lighthouse (via Chrome DevTools)
# Performance tab → Lighthouse
# React Profiler
# React DevTools → Profiler tab
Decision Tree
Performance Issue?
│
├─ Slow page load?
│ ├─ Large bundle → Bundle analysis
│ ├─ Slow API → Database optimization
│ └─ Render blocking → Code splitting
│
├─ Slow interactions?
│ ├─ Long lists → Virtualization
│ ├─ Heavy computation → Web Worker / useMemo
│ └─ Frequent re-renders → React Profiler
│
└─ Layout shifts?
├─ Images → Set dimensions
├─ Fonts → Font preloading
└─ Dynamic content → Skeleton loaders
Common Issues & Solutions
| Issue | Detection | Solution |
|---|---|---|
| Large bundle | > 100KB first load | Dynamic imports, tree shaking |
| Slow renders | React Profiler > 16ms | Memoization, virtualization |
| N+1 queries | Multiple sequential DB calls | Batch queries, denormalization |
| Layout shift | CLS > 0.1 | Fixed dimensions, skeletons |
| Unoptimized images | Large image files | next/image, WebP, responsive |
Related Skills
react-19-compiler- React Compiler optimization guidancefirebase-firestore- Database query patternsstructured-logging- Performance logging
Source
git clone https://github.com/JanSzewczyk/claude-plugins/blob/main/plugins/code-quality/skills/performance-optimization/SKILL.mdView on GitHub Overview
Performance optimization patterns for Next.js applications, covering bundle analysis, React rendering optimization, database query tuning, Core Web Vitals, image optimization, and caching strategies. It emphasizes measurement, bottleneck targeting, user-centric improvements, and iterative, data-driven changes.
How This Skill Works
The skill guides you through metrics-driven optimization: analyze bundles, optimize React rendering paths with memoization and virtualization, and tune database queries. Implement caching, image strategies, and code-splitting to reduce load times and improve interactivity, then iterate with small, measurable changes guided by concrete targets.
When to Use It
- When the initial bundle size is large and slow on first load.
- When API calls or database queries are slow and bottlenecking the app.
- When render-blocking work causes slow interactions and poor responsiveness.
- When Core Web Vitals targets (LCP, INP, CLS) are not being met.
- When long lists or heavy UI components benefit from virtualization and efficient rendering.
Quick Start
- Step 1: Run npm run analyze to measure bundle sizes and identify bottlenecks.
- Step 2: Apply optimizations (dynamic imports, memoization, virtualization, preloading, and caching).
- Step 3: Re-run analysis and Lighthouse, then iterate until targets are met.
Best Practices
- Measure first: collect metrics before making changes.
- Target bottlenecks: focus on the biggest impact areas (bundle, API, render).
- Prioritize user-perceived performance over micro-optimizations.
- Iterate with small, measurable changes to validate impact.
- Adopt proven patterns: dynamic imports, memoization, virtualization, fixed dimensions, and caching.
Example Use Cases
- How to reduce bundle size
- Optimize React rendering
- Fix slow database queries
- Improve Core Web Vitals
- Implement virtualized lists
Frequently Asked Questions
Related Skills
sql-optimization
chaterm/terminal-skills
SQL 优化与调优
tuning
chaterm/terminal-skills
--- name: tuning description: 系统调优 version: 1.0.0 author: terminal-skills tags: [performance, tuning, sysctl, kernel, optimization] --- # 系统调优 ## 概述 内核参数、文件系统、网络优化技能。 ## 内核参数调优 ### 内存管理 ```bash # /etc/sysctl.d/99-memory.conf # 减少交换倾向 vm.swappiness = 10 # 脏页刷新 vm.dirty_ratio = 20 vm.dirty_backg
SEO Audit
openclaw/skills
Full website SEO audit with parallel subagent delegation. Crawls up to 500 pages, detects business type, delegates to 6 specialists, generates health score.
SEO Technical
openclaw/skills
Technical SEO audit across 8 categories: crawlability, indexability, security, URL structure, mobile, Core Web Vitals, structured data, and JavaScript rendering.
smart-sourcing
athola/claude-night-market
balancing accuracy with token efficiency.
python-performance
athola/claude-night-market
'Consult this skill for Python performance profiling and optimization.