Get the FREE Ultimate OpenClaw Setup Guide →
npx machina-cli add skill JanSzewczyk/claude-plugins/performance-optimization --openclaw
Files (1)
SKILL.md
5.0 KB

Performance Optimization Skill

Performance optimization patterns for Next.js applications.

Reference Files:

Performance Philosophy

Principles:

  1. Measure first - Never optimize without metrics
  2. Target bottlenecks - Focus on the biggest impact areas
  3. User-centric - Prioritize perceived performance
  4. 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

MetricTargetOptimization
LCP< 2.5spriority on hero image, preload fonts
INP< 200msstartTransition, defer non-critical JS
CLS< 0.1Fixed dimensions, skeleton loaders

Performance Targets

Bundle Size Targets

CategoryTarget (gzipped)
First Load JS< 100KB
Per-page JS< 50KB
Total app< 300KB
Single dependency< 30KB

Runtime Targets

MetricGoodNeeds 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

IssueDetectionSolution
Large bundle> 100KB first loadDynamic imports, tree shaking
Slow rendersReact Profiler > 16msMemoization, virtualization
N+1 queriesMultiple sequential DB callsBatch queries, denormalization
Layout shiftCLS > 0.1Fixed dimensions, skeletons
Unoptimized imagesLarge image filesnext/image, WebP, responsive

Related Skills

  • react-19-compiler - React Compiler optimization guidance
  • firebase-firestore - Database query patterns
  • structured-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

  1. Step 1: Run npm run analyze to measure bundle sizes and identify bottlenecks.
  2. Step 2: Apply optimizations (dynamic imports, memoization, virtualization, preloading, and caching).
  3. 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

Add this skill to your agents

Related Skills

Sponsor this space

Reach thousands of developers