The Cost of a Re-render Is Not the Re-render
Memoising a component that renders in 0.2ms buys nothing. Here is how to find the render that actually costs you, and why it is usually not the one you suspect.
- React
- Performance
Someone opens a profiler, sees a component rendering forty times, wraps it in
React.memo, and ships. The flame chart looks tidier. The interaction is
exactly as slow as before.
A re-render is cheap. React calls a function and diffs the result - for a typical component that is tens of microseconds. What is expensive is what the render touches.
The three things that actually cost
Layout reads. A component that measures the DOM during render or in a
layout effect forces the browser to flush pending style and layout work
synchronously. One getBoundingClientRect() in a list of 200 rows is 200
forced reflows in one frame.
// ❌ Forced synchronous layout, once per row.
rows.forEach((row) => {
const h = row.getBoundingClientRect().height; // read - flushes layout
row.style.setProperty("--h", `${h}px`); // write - invalidates it
});
// ✅ Batch reads, then batch writes. One layout pass.
const heights = rows.map((row) => row.getBoundingClientRect().height);
rows.forEach((row, i) => row.style.setProperty("--h", `${heights[i]}px`));That read-write interleave is the single most common cause of a janky list, and no amount of memoisation touches it.
Subtree size. memo on a leaf saves a function call. memo on a node with
800 descendants saves 800. The win scales with what is below the component,
which is why memoising the small, obviously-hot component so often does
nothing measurable.
Effect cascades. A useEffect that sets state schedules a second render
pass before paint. Two of those in sequence and a single click costs three
render phases plus two layout passes.
Measure the interaction, not the component
React DevTools shows you render counts. The browser's performance panel shows you what the user experiences. Only one of those is the thing you are trying to fix.
Record the interaction, then look for:
| Signal in the trace | What it means |
|---|---|
Purple Recalculate Style bars between scripts | Layout thrash - a read/write interleave |
| One long yellow block > 50ms | A long task; split it or move it off the main thread |
Commit far wider than Render | The cost is in the DOM mutation, not your components |
| Many short, evenly spaced tasks | Effect cascade or an over-eager subscription |
If the commit phase dominates, memoisation is the wrong tool entirely - you need to produce fewer DOM mutations, usually by virtualising.
A profiler tells you where time went. It cannot tell you whether that time mattered. Always start from an interaction a user complained about.
When memo is right
It earns its keep in exactly two situations: a large subtree whose props are
genuinely stable, and a component that performs expensive work during render
(parsing, formatting, sorting) that cannot move to a useMemo.
Everywhere else, the honest ranking of what to fix is: stop thrashing layout, render fewer nodes, then - distantly - render them less often.