Profiling Before and After Memoization
You'll learn how to use React DevTools Profiler recordings to measure the actual performance impact of your useMemo and useCallback optimizations.
Why Compare Before and After
Adding useMemo or useCallback isn't automatically beneficial—it adds overhead. The only way to know if your memoization actually helped is to measure render times before and after applying it. Without profiler evidence, you're optimizing blind.
The Comparison Process
Before recording: Profile your component's render behavior without memoization. Note the render count, duration, and flamegraph shape for the slow component.
After recording: Add your useMemo or useCallback, then profile the same interaction again. Compare:
- Render count: Did child components stop re-rendering?
- Render duration: Did the expensive computation time disappear?
- Commit duration: Did the overall update become faster?
Look at the flamegraph's width (duration) and the ranked chart's millisecond values. A successful optimization shows measurably shorter bars and lower totals.
What Success Looks Like
If your memoization worked, you'll see:
- Fewer commits in the profiler timeline
- Reduced render time for the component with the expensive calculation
- Child components appearing gray (didn't render) when props stay stable
If you see no difference—or worse, slightly longer renders—the memoization cost more than it saved. Remove it.
The Profiler Is Your Source of Truth
Don't assume useMemo helps. Measure small computations that seem expensive but finish in 0.1ms—memoization's overhead exceeds their cost. Let the profiler tell you whether your optimization was worth it.
Key Takeaway: Always record profiler sessions before and after adding memoization; only keep the optimization if the after recording shows measurably faster render times or fewer unnecessary renders.