Chapter 4 · Practice 3 of 5
Measure with the React Profiler before you optimize
Why it matters
Guessing where a slow screen spends its time usually leads to the wrong fix. Measure first.
- Open React DevTools and record a profile while you reproduce the slow interaction.
- Look at which components rendered and how long each took.
- Fix the biggest cost first.
- Measure again so you know the change helped.
Common real causes are:
- a large list rendering every row,
- state placed too high in the tree,
- an expensive calculation in a component that renders often.
Check a production build too. Development builds are slower and include extra checks.
Do
- Profile a production build before and after each change
- Virtualize lists with hundreds of rows
Avoid
- Optimizing components that render in under a millisecond