React / 98
Profiling: measure before you optimise
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
2
Find why
3
Fix one thing
4
Measure again
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
Start recording
Click the round record button in the Profiler tab.Do the slow thing once
Type one letter, open the menu, add one item. Keep the recording short so it's easy to read.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.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 itApp 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.
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 shows | Likely cause | Fix |
|---|---|---|
| Everything renders on each keystroke | State lives high in the tree | Move the state down into the component that uses it |
A memo child renders, "Props changed: (onSelect)" | A new function or object every render | useCallback / useMemo, or move constants outside the component (how) |
| One list component is very wide | Thousands of rows rendered at once | Virtualise: render only the visible rows (TanStack Virtual, react-window) |
| One component is slow on its own | Heavy calculation during render | useMemo for the result, or useDeferredValue / startTransition to keep typing responsive (how) |
| Slow first load, not slow updates | A big JavaScript bundle | Code-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:
| Metric | Measures | Good |
|---|---|---|
| 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.
