Performance
Finding slow renders.
React is fast by default. When an app does feel slow, don't guess. Measure first, find the component that's actually slow, and fix just that.
- Fast by default
- Don't guess
- Measure first
The performance loop
Measure with the profiler. Find the slow component. Apply one fix. Then measure again, to prove it helped.
- Measure
- Find
- Fix
- Measure again
React DevTools Profiler
Install the React developer tools browser extension. The profiler tab records a session, and shows every render, and how long each component took. Highlight updates shows which parts of the page re-render as you use it.
| key | value |
|---|---|
| Install | React DevTools |
| Profiler | records renders |
| Shows | time per component |
| Highlight | what re-renders |
Common fixes
Move state down, closer to where it's used, so less re-renders. Use memo for genuinely slow calculations. Show long lists in pages, or with a virtual list. And load big parts later, with lazy.
| Problem | Fix |
|---|---|
| Too much re-renders | move state down |
| Slow calculation | useMemo |
| Huge list | paginate or virtualize |
| Big bundle | lazy() |
Summary
Measure with the profiler, fix the slowest part, and measure again. Next, accessibility.
Key takeaways- Profiler
- One fix
- Measure again