Skip to content
ClapelloNotes by Barath
ReactCh 17 · 5/6
Deep dive4 min readUpdated

React / 98

Profiling: measure before you optimise

TL;DR

Use the React DevTools Profiler to see which components rendered, how long they took and why, then fix the real culprit instead of guessing.

1

Measure

Record the slow interaction in the Profiler.
biggest bar

2

Find why

Which component, and why did it render?
one change

3

Fix one thing

Move state down, memo, virtualise…
compare

4

Measure again

Faster? Keep it. Not faster? Undo it.
Never fix a guess. Record what's slow, change one thing, and record again to prove it helped.

Set up

Install the React Developer Tools browser extension (Chrome, Firefox or Edge). Your browser's DevTools gets two new tabs: Components (the component tree, with props and state) and Profiler.

Before your first recording, open the Profiler's settings (the gear icon) and tick "Record why each component rendered while profiling". Without it, you see what rendered but not why.

Record one slow interaction

  1. Start recording

    Click the round record button in the Profiler tab.
  2. Do the slow thing once

    Type one letter, open the menu, add one item. Keep the recording short so it's easy to read.
  3. Stop

    The bar chart at the top shows one bar per commit (each time React updated the page). Taller bars are slower. Click the tallest.
  4. Read the flamegraph

    Find the widest coloured bar under the commit, select it, and read why it rendered.

Here's what a recording might show for typing one letter into a delivery-note field, with the data simulated so you can try each fix:

Profile one keystroke

Try it

App holds the note state. Nothing memoised.

render duration38.7 ms

305 of 305 components rendered

  • rendered, slow
  • rendered, fast
  • did not render

selected · MenuList

Rendered in 1.2 ms (its own work, without children).

why did this render? The parent component rendered.

Simulated Profiler data for typing one letter into a delivery note. Pick a fix, then tap any bar to see why it rendered. Bar width is how long it and its children take; grey means it was skipped.

How to read it:

  • Width: how long the component and its children took. Wide bars are where the time went.
  • Colour: its own render time. The real Profiler uses warm yellow for slow and cool blue-green for fast. Grey means it didn't render in this commit, which is what you want for anything unaffected.
  • Why did this render? One of: "This is the first time the component rendered", "Props changed" (with the prop names), "Hook N changed" (state or another hook), "Context changed", or "The parent component rendered".

The Ranked view lists the same components sorted slowest first, which is handy in big trees.

Common culprits

What the Profiler showsLikely causeFix
Everything renders on each keystrokeState lives high in the treeMove the state down into the component that uses it
A memo child renders, "Props changed: (onSelect)"A new function or object every renderuseCallback / useMemo, or move constants outside the component (how)
One list component is very wideThousands of rows rendered at onceVirtualise: render only the visible rows (TanStack Virtual, react-window)
One component is slow on its ownHeavy calculation during renderuseMemo for the result, or useDeferredValue / startTransition to keep typing responsive (how)
Slow first load, not slow updatesA big JavaScript bundleCode-split with lazy (how)

Moving state down is often the best fix, as the demo shows: nothing to compare, nothing to memoise, and far fewer components render at all.

Where the React Compiler fits

The React Compiler is a build plugin that memoises components and values automatically. It removes most of the "Props changed" and "The parent component rendered" re-renders you'd otherwise fix by hand with memo, useMemo and useCallback (details). Components it optimised show a "Memo ✨" badge in DevTools.

It can't make necessary work cheap. A list of 5,000 rows still renders 5,000 rows, a slow calculation is still slow the first time, and a slow API is still slow. You still profile; you just find fewer problems.

Beyond React: Web Vitals

The Profiler measures React's work. Users feel the whole page. Google's Core Web Vitals measure that:

MetricMeasuresGood
LCP (Largest Contentful Paint)When the main content appears≤ 2.5 s
INP (Interaction to Next Paint)How fast the page responds to clicks and key presses≤ 200 ms
CLS (Cumulative Layout Shift)How much things jump around while loading≤ 0.1

Run Lighthouse in Chrome DevTools for a lab report. Slow React renders usually show up as poor INP. For deeper digging, Chrome's Performance panel shows React's own tracks (scheduler and component renders) next to everything else the browser did, since React 19.2.

Gotchas

Recall

Can you answer these?

0/5

Answer out loud (or in your head) before you tap. That's what makes it stick.

Saved on this device only. No login.