Sub topic 11
Reading the flamegraph and ranked charts
This chapter assumes you can write function components, use useState and props, and have recorded a Profiler session in a development or profiling build. Here you learn to read the two main views of a recording: the flamegraph and the ranked chart.
What a commit is
React groups its work into commits. A commit is one pass where React applies changes to the screen. The Profiler shows one bar per commit at the top right. Click a bar to see that commit's charts. A taller, yellower bar means a slower commit. Commits with no bar height change were cheap.
The flamegraph
The flamegraph mirrors your component tree for the selected commit. The root sits at the top and children sit below their parents. Each bar is one component.
- Width shows how long the component and its children took to render.
- Color shows how long the component itself took. Cooler colors (blue, green) are fast. Warmer colors (yellow, orange) are slow.
- Gray means the component did not render in this commit. React reused its previous output.
Gray bars are the useful signal. If you expected a component to stay still and it is colored, it re-rendered.
The ranked chart
The ranked chart shows the same commit as a flat list. Components are sorted by their own render time, with the slowest at the top. Components that did not render in the commit are left out.
Use it when you want to answer "what was slowest?" without walking the tree. Use the flamegraph when you want to answer "where in the tree did the work happen?"
| Question | Best view |
|---|---|
| Which component took the longest? | Ranked chart |
| Did this component re-render? | Flamegraph (gray or colored) |
| Which subtree did the work? | Flamegraph |
| What should I optimize first? | Ranked chart |
Reading the numbers
Hover over a bar to see a tooltip. It shows the component name and two times: the time spent rendering this component alone ("self") and the time including its children. If self time is small but total time is large, the cost is in the children. Look further down the tree.
Select a component to see more in the right-hand panel. It lists the commits in which that component rendered and, if you enabled it, why it rendered. The next chapter covers render reasons.
Common errors
- Optimizing the wrong thing. A wide bar in a parent can come entirely from its children. Check self time before changing the parent.
- Trusting development timings. Development builds are slower than production. Use the numbers to compare components with each other, not as real-world speeds.
- Reading the wrong commit. The charts change when you click a different commit bar. If the data looks wrong, check which commit is selected.
- Assuming gray means broken. Gray is the desired result for components that have no new data.
A quick example
Take the List component from the memoization examples. Record one click on an item. In the flamegraph, if every Item is colored, then every item re-rendered even though only one changed. Switch to the ranked chart and you see many Item entries with similar small times. The count is the problem, not any single slow item.
Exercise
In a Profiler flamegraph, a component bar is gray. What does that tell you, and which chart would you use to find the slowest component in a commit?
Show answer
Gray means the component did not render in that commit, because React reused its previous output. To find the slowest component, use the ranked chart, which sorts rendered components by their own render time.
Exercise
A parent component has a wide flamegraph bar, but its own (self) time in the tooltip is very small. Where should you look next?
Show answer
Look at its children. The width includes child render time, so the cost comes from components lower in the tree.