All skills
dimillian avatar

/react-component-performance

@3db84e6 official
by Thomas Ricouarddimillian/skills4k stars
206

Analyze and optimize React component performance issues (slow renders, re-render thrash, laggy lists, expensive computations). Use when asked to profile or improve a React component, reduce re-renders, or speed up UI updates in React apps.

Use this Skill: https://skilld.dev/gh/dimillian/skills/react-component-performance

This session only. Nothing lands on disk.

SKILL.md

≈67 tokens always: the name and description. ≈1.1k when used: this file. ≈655 more on demand in 2 files.

React Component Performance

Overview

Identify render hotspots, isolate expensive updates, and apply targeted optimizations without changing UI behavior.

Workflow

  1. Reproduce or describe the slowdown.
  2. Identify what triggers re-renders (state updates, props churn, effects).
  3. Isolate fast-changing state from heavy subtrees.
  4. Stabilize props and handlers; memoize where it pays off.
  5. Reduce expensive work (computation, DOM size, list length).
  6. Validate: open React DevTools Profiler → record the interaction → inspect the Flamegraph for components rendering longer than ~16 ms → compare against a pre-optimization baseline recording.

Checklist

  • Measure: use React DevTools Profiler or log renders; capture baseline.
  • Find churn: identify state updated on a timer, scroll, input, or animation.
  • Split: move ticking state into a child; keep heavy lists static.
  • Memoize: wrap leaf rows with memo only when props are stable.
  • Stabilize props: use useCallback/useMemo for handlers and derived values.
  • Avoid derived work in render: precompute, or compute inside memoized helpers.
  • Control list size: window/virtualize long lists; avoid rendering hidden items.
  • Keys: ensure stable keys; avoid index when order can change.
  • Effects: verify dependency arrays; avoid effects that re-run on every render.
  • Style/layout: watch for expensive layout thrash or large Markdown/diff renders.

Optimization Patterns

Isolate ticking state

Move a timer or animation counter into a child so the parent list never re-renders on each tick.

// ❌ Before – entire parent (and list) re-renders every second
function Dashboard({ items }: { items: Item[] }) {
  const [tick, setTick] = useState(0);
  useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 1000);
    return () => clearInterval(id);
  }, []);
  return (
    <>
      <Clock tick={tick} />
      <ExpensiveList items={items} /> {/* re-renders every second */}
    </>
  );
}

// ✅ After – only <Clock> re-renders; list is untouched
function Clock() {
  const [tick, setTick] = useState(0);
  useEffect(() => {
    const id = setInterval(() => setTick(t => t + 1), 1000);
    return () => clearInterval(id);
  }, []);
  return <span>{tick}s</span>;
}

function Dashboard({ items }: { items: Item[] }) {
  return (
    <>
      <Clock />
      <ExpensiveList items={items} />
    </>
  );
}

Stabilize callbacks with useCallback + memo

// ❌ Before – new handler reference on every render busts Row memo
function List({ items }: { items: Item[] }) {
  const handleClick = (id: string) => console.log(id); // new ref each render
  return items.map(item => <Row key={item.id} item={item} onClick={handleClick} />);
}

// ✅ After – stable handler; Row only re-renders when its own item changes
const Row = memo(({ item, onClick }: RowProps) => (
  <li onClick={() => onClick(item.id)}>{item.name}</li>
));

function List({ items }: { items: Item[] }) {
  const handleClick = useCallback((id: string) => console.log(id), []);
  return items.map(item => <Row key={item.id} item={item} onClick={handleClick} />);
}

Prefer derived data outside render

// ❌ Before – recomputes on every render
function Summary({ orders }: { orders: Order[] }) {
  const total = orders.reduce((sum, o) => sum + o.amount, 0); // runs every render
  return <p>Total: {total}</p>;
}

// ✅ After – recomputes only when orders changes
function Summary({ orders }: { orders: Order[] }) {
  const total = useMemo(() => orders.reduce((sum, o) => sum + o.amount, 0), [orders]);
  return <p>Total: {total}</p>;
}

Additional patterns

  • Split rows: extract list rows into memoized components with narrow props.
  • Defer heavy rendering: lazy-render or collapse expensive content until expanded.

Profiling Validation Steps

  1. Open React DevTools → Profiler tab.
  2. Click Record, perform the slow interaction, then Stop.
  3. Switch to Flamegraph view; any bar labeled with a component and time > ~16 ms is a candidate.
  4. Use Ranked chart to sort by self render time and target the top offenders.
  5. Apply one optimization at a time, re-record, and compare render counts and durations against the baseline.

Example Reference

Load references/examples.md when the user wants a concrete refactor example.

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is safe. It provides guidelines and examples for optimizing React component performance. No security issues, malicious patterns, or suspicious external references were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    1/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 3db84e6. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 7 months ago

README badge

README badge for dimillian/skills/react-component-performance

Identify render bottlenecks in React components using React DevTools Profiler and apply targeted optimizations like isolating ticking state, stabilizing callbacks with useCallback, and memoizing expensive computations. Use when a React component is slow, re-renders excessively, or has laggy list rendering.

Generated from the current SKILL.md.

Does this skill work with Next.js or other React frameworks?
Yes. The skill targets React component rendering itself, so it applies to any framework built on React, including Next.js, Remix, and Gatsby.
What tools do I need to profile with this skill?
React DevTools Profiler (a browser extension) is the primary tool. The skill uses its Flamegraph and Ranked chart views to identify slow components.
Does this cover server components or only client-side rendering?
The skill focuses on client-side React component performance. Server component optimization falls outside its scope.
Will this skill help with bundle size or initial page load?
No. The skill targets runtime performance of existing components—slow renders, re-render churn, and laggy interactions. For bundle size, see code-splitting or tree-shaking tools.
Can I apply these optimizations to class components?
The examples use hooks (useState, useCallback, useMemo), which are for functional components. Class components use shouldComponentUpdate and PureComponent instead, though the underlying principles are the same.

Generated from the current SKILL.md. These answers refresh after source changes.