react-performance-optimizations
Techniques for Virtualization, Memoization, and RSC logic. Use when optimizing a sluggish React app or refactoring to server components.
Files1
View on GitHubSKILL.mdskills/react-performance-optimizations/SKILL.md
GitHubReact Performance Optimizations (Redesigned)
Purpose
Enforce strict performance standards for React and Next.js applications through architectural state minimization rather than blind memoization.
Hard Usage Rules (Tier 3: Unsafe without Diagnostics)
- ALLOWED: ONLY when the user explicitly provides a React Profiler trace or identifies a specific render loop.
- FORBIDDEN: General usage or preemptive "optimization" passes on working code.
- CONSTRAINT: ABORT execution if invoked without profiling data or explicit render loop identification.
New Execution Strategy (Measure-First)
- Refuse Optimization: Do not write
useMemooruseCallbackunless diagnostics are provided. - Component Splitting First: Push state down to the lowest possible leaf node. If a state update does not affect the parent, it must be moved out of the parent.
- Memoization as Last Resort: If memoization is absolutely forced, run a strict static analysis pass over the dependency array before outputting.
Safety Guardrails & Patched Prevention
- Stale Closure Patch: Never use
useCallbackwithout verifying that all referenced variables inside the closure are included in the dependency array. If tracing scope is impossible due to missing context, do not memoize. - Self-Rejection Clause: If state can be pushed down to a child component, DO NOT use
useMemo. If dependency correctness cannot be guaranteed, ABORT OUTPUT.
When to Use This Skill
Use when optimizing a sluggish React app or refactoring to server components, specifically when you have diagnostics or profiling data.
Phase 1: Optimization and State Splitting
- Refuse optimization without diagnostics.
- Push state down to the lowest possible leaf node. If a state update does not affect the parent, it must be moved out of the parent.
- If memoization is forced, run static analysis on dependencies.
Behavior Rules
- Measure First: Always rely on profiling data before applying any optimization logic.
- Component Splitting First: Prefer structural changes (component isolation) over hook-based caching (
useMemo/useCallback). - No Premature Optimization: Do not memoize anything "just in case".
Output Format / Delivery
- The output should be a targeted, structurally refactored component block.
Maintenance Notes
- Complete redesign from v1 to v2. Abandoned blind memoization strategy in favor of Component Splitting and Measure-First execution.