The Cost of React.memo Itself
You'll learn: React.memo isn't free—it performs a shallow comparison on every render, and sometimes that overhead costs more than just re-rendering.
The Hidden Tax
When you wrap a component with React.memo, React must compare all props (shallowly) on every parent render to decide whether to skip rendering your component. This comparison itself takes time—checking each prop's reference equality, iterating through the prop object, and making a decision.
For simple components that render quickly (a few milliseconds or less), this comparison overhead can actually be slower than just letting the component re-render naturally.
The Break-Even Point
Think of it like hiring a consultant to decide whether you need to do a task. If the task takes 2 minutes but the consultant takes 3 minutes to evaluate it, you've lost time. Similarly, if your component renders in 1ms but the shallow comparison takes 0.5ms, and the component would have re-rendered with identical output anyway, you've wasted 0.5ms for no benefit.
When the Math Works Out
React.memo pays off when:
- The component is expensive to render (10ms+)
- Props change infrequently relative to parent renders
- The component is deep in the tree (preventing cascading re-renders)
It usually doesn't pay off for:
- Tiny presentational components (buttons, labels, simple divs)
- Components that render in under 5ms
- Components whose props change on most parent renders anyway
Measure Before Optimizing
Use the Profiler to compare render times with and without React.memo. If you don't see a meaningful improvement (or worse, a regression), remove it. The comparison overhead is real.
Key Takeaway: React.memo adds a shallow comparison cost on every render; only use it when the re-render cost is demonstrably higher than the comparison overhead.