Skip to content

Lesson 2 of 9 · 27m

Profiling React Renders Without Fooling Yourself

Use the React DevTools Profiler and browser performance panel together to distinguish render cost, commit cost, effects, and browser layout work.

React developers often profile the way people check a pulse during a house fire: one tap, one number, immediate panic. The Profiler is valuable, but it only shows part of the system. React can render in 8 ms and still miss the frame because effects, layout, paint, images, or a giant DOM consume the rest. Treat profiling as reconstruction, not scorekeeping.

Prepare a reproducible interaction

Before recording, define one user action:

route: /tickets?status=open
action: type "refund" in search, one keystroke per 250 ms
device: 4x CPU throttle
data: tenant fixture with 4,000 tickets

Without this discipline you will compare different interactions and conclude nonsense. Clear cache only for cold-load tests; warm-cache interactions usually represent repeated product use better.

Read the React Profiler correctly

Record a profile, perform the interaction, then inspect the flamegraph and ranked chart. Ask:

Which components rendered?
How much self time did each component spend?
Why did each component render?

"Why did this render?" is the crucial question. A component with 0.2 ms self time that renders 3,000 times is not cheap. A 20 ms leaf that renders once may be the real bottleneck.

Do not stop at React's commit boundary

The browser performance panel shows what happened around the commit:

React render work       component execution and reconciliation
commit phase            DOM mutations and layout effects
style/layout            browser recalculation after DOM reads/writes
paint/composite         pixels, layers, scrolling
network/parse           JavaScript fetch, parse, compile, execution

Look for long tasks, red layout warnings, dropped frames, and forced synchronous layout. A common smell is an effect that writes layout, reads layout, then writes again:

useLayoutEffect(() => {
  node.style.height = 'auto'
  const height = node.getBoundingClientRect().height
  node.style.height = `${height}px`
}, [open])

Sometimes measurement is necessary. Often it means animation state is being coordinated through the DOM instead of once through state and CSS transitions.

Production evidence differs

Development builds exaggerate render cost, and strict mode intentionally double-invokes some work. Profile a production build when conclusions matter. Around critical interactions, lightweight marks can connect user experience to code changes:

performance.mark('ticket-search:start')
updateSearch(value)
requestAnimationFrame(() => performance.measure('ticket-search', 'ticket-search:start'))

Profile populated states, not merely the empty first mount. Keep fixtures that represent your largest reasonable customer.

Field notes

  • React Profiler time is not wall-clock user latency; use it with the browser timeline.
  • Strict-mode double rendering can make a healthy screen look twice as expensive in development.
  • If a child renders because "parent rendered," walk upward; ownership is usually the mistake.
  • Save traces before changing code. Human memory is a terrible profiler.

Was this lesson helpful?

Sign in to rate