tezvyn:

React Profiler long render duration: causes and next steps?

AI-drafted, machine-checkedSource: react.devintermediate
React Profiler long render duration: causes and next steps?

Tests interpreting actualDuration vs baseDuration. Outline: close values on updates mean broken memoization—add memo or useMemo; high baseDuration alone means an inherently slow subtree. Red flag: proposing fixes before comparing these two Profiler metrics.

WHAT THIS TESTS: whether you treat Profiler data as a diagnostic signal rather than a raw number. The interviewer cares if you know that actualDuration and baseDuration are meant to be compared, and that phase tells you whether you are looking at a mount or an update.

A GOOD ANSWER COVERS: four things in order. First, explain that actualDuration is the milliseconds React spent rendering the profiled subtree for the current commit, while baseDuration estimates the milliseconds it would take to re-render the entire subtree without any optimizations like memo or useMemo. Second, compare the two numbers during an update phase. If actualDuration is close to baseDuration, memoization is not working and many descendants are re-rendering unnecessarily; the next step is to add memo or useMemo and verify that actualDuration drops while baseDuration stays roughly the same. Third, if baseDuration itself is high even when actualDuration is low, the component tree is inherently expensive to render regardless of memoization; the next step is to reduce what the subtree renders. Fourth, check the phase parameter. A high duration during mount is expected because every component must render for the first time, whereas a high duration during update is the real regression to fix.

COMMON WRONG ANSWERS: three patterns. First, ignoring the actualDuration versus baseDuration comparison and proposing unrelated changes instead. Second, treating a high mount phase duration as an update regression and adding memoization where it cannot help on initial render. Third, forgetting that profiling adds overhead and is disabled in production by default, so metrics should be validated in a profiling-enabled build.

LIKELY FOLLOW-UPS: the interviewer might ask how you would verify that memo is actually preventing re-renders, or what you would do if actualDuration is low but the UI still feels sluggish, or how you enable profiling in a production build.

ONE CONCRETE EXAMPLE: you profile a dashboard widget and see an actualDuration of 80 milliseconds and a baseDuration of 78 milliseconds on every filter update. Because the values are nearly identical, you conclude memoization is failing. You wrap the child list in memo and memoize the computed data with useMemo. On the next update, actualDuration falls to 4 milliseconds while baseDuration remains 75 milliseconds, confirming the subtree is still expensive in theory but now skipped in practice.

Read the original → react.dev

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.