Sub topic 5
Reading the flame chart
This chapter assumes you can open the Performance panel and record a trace of a production-like build, as covered in earlier chapters. You should also know what the browser main thread and event loop are.
What the flame chart shows
The flame chart is the Main track of a Performance recording. It plots the call stack of the main thread over time.
- The horizontal axis is time. A wider bar ran for longer.
- The vertical axis is stack depth. A bar sits directly below the function that called it.
- The top bar of a stack is the entry point, such as an event handler or a timer callback. The bars at the bottom are the functions that were running at that moment.
Width tells you where time went. Depth tells you why that code ran.
Total time and self time
Each bar has two durations, and you will see both in the Summary tab when you select a bar.
| Measure | Meaning | Use it to find |
|---|---|---|
| Total time | The function plus everything it called | Which entry point is slow overall |
| Self time | Only the time spent in the function's own code | The function that does the heavy work |
A wide bar with a narrow bar of equal width under it means the parent only delegated the work. Follow the stack down to the lowest wide bar. That function usually holds the cost.
Navigating the chart
- Drag across the overview at the top to zoom into a time range.
- Use
WandSto zoom in and out, andAandDto pan left and right. - Click a bar to see its name, durations, and source location in the Summary tab.
- Open the Bottom-Up tab to list functions sorted by self time. Open Call Tree to see the same data grouped by caller.
If you profiled with source maps, the names refer to your TypeScript files. Click the link in the Summary tab to open the source.
Colors and markers
Bars are colored by activity type. Yellow is JavaScript, purple is rendering work such as style and layout, and green is painting. A tall yellow stack followed by a purple block often means your code changed the DOM and forced the browser to recompute layout.
A red triangle in the corner of a task flags it as a long task. The next chapter covers these in detail.
Finding your own code
Angular framework functions fill most stacks, so your code can be hard to spot. Wrap suspect code in User Timing calls to label it:
filterItems(term: string) {
performance.mark('filter-start');
const result = this.items.filter(i => i.name.includes(term));
performance.measure('filter', 'filter-start');
return result;
}The Timings track then shows a filter entry. Its width matches the call, so you can line it up with the stack in the Main track.
Common mistakes
- Reading width as importance. A narrow function called thousands of times can cost more than one wide bar. Check Bottom-Up to see totals per function.
- Profiling a development build. Extra checks make the stacks deeper and the widths larger, so the picture misleads you.
- Zoomed-out conclusions. At full zoom, tiny bars merge. Zoom into one task before judging it.
Exercise
In the flame chart, a bar for onSearch is 80 ms wide. Directly beneath it is a bar for filterItems that is also about 80 ms wide. Which one has the higher self time, and how would you confirm it?
Show answer
filterItems has the higher self time. onSearch spent almost all its total time waiting on the function it called, so its own code took little. Select each bar and compare the Self Time value in the Summary tab, or sort the Bottom-Up tab by self time.