Sub topic 13
Going beyond React: the browser Performance panel
This chapter assumes you can record a React DevTools Profiler session and read its flamegraph, and that you know the difference between development and production builds. The React Profiler only sees React work. When a page feels slow for another reason, the browser Performance panel shows the whole picture.
What the React Profiler cannot see
The React Profiler measures render time for components. It does not measure:
- Script work outside React, such as parsing JSON or running analytics code.
- Style calculation, layout, and paint, which happen after React commits to the DOM.
- Network time and script download time.
- Long tasks, which are pieces of JavaScript that block the main thread for more than 50 ms.
If the Profiler shows fast renders but the interface still stutters, the cause is probably in this list.
Recording a trace
Profile a production build when you can, because development builds add extra checks that distort timings.
- Open DevTools and choose the Performance tab.
- Optionally set CPU throttling (for example 4x slowdown) to mimic a slower device.
- Click Record, perform the slow interaction, then click Stop. For load problems, use the reload-and-record button instead.
- Keep recordings short and focused on one interaction. Long traces are hard to read.
Reading the trace
The main areas of the panel are:
| Area | What it shows | What to look for |
|---|---|---|
| Frames or screenshots | What the user saw over time | Gaps where nothing changed |
| Network | Request timing | Large or late scripts |
| Main | The call stack on the main thread, drawn as a flamegraph | Tasks marked with a red corner |
| Summary tab | Time split into scripting, rendering, painting, and idle | A dominant category |
The Main track works like the React flamegraph. Wider blocks took longer, and blocks stacked below a block were called by it. A task with a red marker is a long task. Click it, then read the Bottom-Up tab to see which functions used the most self time.
Matching symptoms to causes
Use the Summary tab to decide where to look next.
- Mostly scripting, with React function names in the stack: go back to the React Profiler and reduce renders.
- Mostly scripting, with your own non-React functions: optimize that code, or move it off the main thread.
- Large rendering time: look for layout thrashing, where code reads layout values such as
offsetHeightand then writes styles in a loop, forcing repeated layout. - Long scripting during page load: the bundle is too big. This leads to code splitting, covered in the next chapter.
Marking your own work
You can add named spans to the trace with the User Timing API. They show up in the Timings track, so you can find your code quickly.
function filterRows(rows, query) {
performance.mark("filter-start");
const result = rows.filter((row) => row.name.includes(query));
performance.mark("filter-end");
performance.measure("filterRows", "filter-start", "filter-end");
return result;
}While a trace is recording, a filterRows entry appears in the Timings track with its duration.
Exercise
The React Profiler shows every component rendering in under 2 ms, yet clicking a button still freezes the page for about 300 ms. In a Performance panel trace, what do you look for first, and what does it tell you?
Show answer
Look for a long task (a red-marked block on the Main track) that starts at the click. Open its Bottom-Up tab to find the functions with the most self time. Because React renders are fast, the time is probably in non-React scripting, in layout and style work, or in a heavy event handler, and the call stack names the function responsible.