Sub topic 1
Why Measure Before You Optimize
Prerequisites
You should know JavaScript functions and arrays, React function components, props, state, hooks, and basic browser developer tools.
Why Measure Before You Optimize
Performance work should begin with evidence. A slow page may come from React rendering, network requests, JavaScript calculations, layout, or large assets. Changing code without measuring can fix the wrong problem or make the code harder to maintain.
Record a baseline first. Choose a user action, such as typing in a search box, and measure it consistently. Note the component that feels slow, the duration, and the conditions used. Then make one focused change and measure the same action again.
How React Renders and Commits
A render is React calculating what the user interface should look like after props or state change. React calls components and builds a new element tree. A render does not necessarily change the browser page.
A commit is when React applies the needed changes to the DOM, the browser's document structure. React may render a component even when the final DOM changes very little. Extra renders consume CPU time, while large DOM updates can also delay painting.
Development and Production Builds: What Your Numbers Mean
Development builds include warnings, extra checks, and debugging behavior. In some configurations, React Strict Mode also calls certain logic more than once to expose unsafe side effects. These timings help find problems but do not represent production speed.
Production builds remove much of this diagnostic work and use optimized React code. Compare before-and-after results in the same build. Use development tools to locate suspicious components, then confirm important improvements in a production-like build.
Recording a Session with the React DevTools Profiler
Install the React Developer Tools browser extension and open its Profiler tab. Select Start profiling, perform one representative interaction, and select Stop profiling. The profiler records commits and shows how much time components used.
Use the flamegraph to see component relationships and render cost for a commit. Use the ranked view to find components with the highest individual costs. Select a component to inspect its render details and, when available, why it rendered. Look for repeated expensive work rather than assuming every highlighted component needs a fix.
Exercise
Why should you avoid judging an optimization from a development-build timing alone?
Show answer
Development builds add diagnostic work and may repeat component logic, so their timings do not represent production behavior. Compare matching builds and verify the result in production-like conditions.