Sub topic 5
Reading the flame chart
This chapter assumes you can already record a trace in the Performance panel (covered in the previous chapter) and that you know what a component, a template binding, and a change detection pass are. You don't need to know how Zone.js works yet. That comes later in the tutorial.
What the flame chart shows
The flame chart is the view of the Main track in a recording. It draws every function the browser's main thread ran, on two axes:
- The horizontal axis is time. A bar's width is how long that function was on the stack.
- The vertical axis is call depth. A bar sits directly under the function that called it.
Bars at the top are callers, and bars at the bottom are the functions they called. A tall stack means deep nesting. It does not mean slow code. Only width tells you about cost.
A bar is not a single call. The profiler samples the stack at short intervals, then merges consecutive samples that share the same function into one bar. A wide bar can therefore be one slow call or several adjacent calls to the same function. Use the Call Tree tab (described below) to tell them apart.
Colors and what they mean
In the Performance panel, the color of a bar tells you what kind of work it was.
| Color | Category | Typical cause in an Angular app |
|---|---|---|
| Yellow | Scripting | Your code, Angular, and library JavaScript |
| Purple | Rendering | Style recalculation and layout |
| Green | Painting | Paint and compositing |
| Gray | Other or system | Idle gaps, browser internals |
Most of a slow Angular interaction is yellow. If you see large purple blocks after the yellow, the DOM changes made by your code are forcing layout work. Large purple blocks can also appear inside the yellow when code reads layout properties, such as offsetHeight, right after writing to the DOM.
Anatomy of one interaction
Click a button that updates the page, and the flame chart usually looks like this:
- A Task bar at the very top. A task is one unit of work the browser takes off its queue.
- Under it, an Event bar such as
click, then a Function Call bar. - Under that, Zone.js and Angular frames, then your handler and the change detection pass that follows it.
The bar at the bottom of a stack is usually the one that matters. If a parent is 80 ms wide and its widest child is 78 ms wide, the parent's own code costs about 2 ms. The child is where the time went.
Total time and self time
Every function has two costs:
- Total time is the width of its bar. It includes everything it called.
- Self time is the part of that width not covered by children. It is the exposed "flat top" of a bar.
Look for bars with a large flat top and nothing beneath them. Those are the places where the CPU spent time in that function's own code. A function that has large total time but little self time is only passing the cost down to its children.
A worked example
This component has a template method that is deliberately slow, so you can find it in a trace.
import { Component, signal } from '@angular/core';
@Component({
selector: 'app-report',
template: `
<button (click)="refresh()">Refresh</button>
<p>Score: {{ score() }}</p>
<p>Updated: {{ updates() }}</p>
`,
})
export class ReportComponent {
updates = signal(0);
score(): number {
let total = 0;
for (let i = 0; i < 5_000_000; i++) {
total += Math.sqrt(i);
}
return Math.round(total);
}
refresh() {
this.updates.update(n => n + 1);
}
}Record a trace in a production-like build, click Refresh once, and stop recording. Then:
- Find the
clicktask in the Main track and zoom in on it with the mouse wheel, or drag a selection across the timeline overview. - Follow the stack down from the task. The widest chain passes through Angular's change detection and into the template function for
ReportComponent. - At the bottom you will see
score, with a wide, flat top. That is the cost. The click handlerrefreshis a thin sliver, because it only increments a signal.
The click handler is cheap. The cost sits in a function that runs during rendering, not in the handler that triggered the update. This is a common pattern in Angular apps, and the flame chart is how you see it.
Using the tabs under the chart
The summary panel under the flame chart answers questions the chart alone cannot:
- Call Tree shows the same stacks as a tree, top-down, with total and self time per function. Use it to see how many calls a merged bar contains.
- Bottom-Up lists functions by self time across your selection, with callers nested under each. Sort by Self Time and the most expensive function in the range is at the top. This is often the quickest way to a hot spot.
- Event Log lists events in time order, which helps when you need to confirm what happened first.
Select a range before you read these tabs. With no selection, they summarize the whole recording and the numbers are dominated by idle time and startup.
Recognizing Angular frames
Function names vary with the Angular version and with whether the build is minified, so treat the names below as things to look for, not as a fixed list. In a development build you can usually find:
- Frames from
zone.js, such asZoneDelegate.invokeTask, near the top of the stack. These show how the work entered Angular. - A frame for the application tick, often named
ApplicationRef.tick, that wraps one change detection pass. - Frames such as
refreshViewandexecuteTemplate, which run component templates. - Your own component methods, called from inside those template frames.
Development builds also run a second verification pass after each tick, so the same work can appear twice. Do not count that second pass as a cost your users pay. This is one reason to profile a production-like build.
Pitfalls when reading the chart
- Minified names. Without source maps, bars are labeled with short names such as
aorIe. Serve source maps in the build you profile so names match your code. - Missing short functions. Sampling can skip functions that run for less than the sampling interval. A repeated tiny call can add up without ever showing as its own bar. The Bottom-Up tab can still reveal it as a large aggregate.
- Throttling changes widths. A CPU slowdown stretches every bar. Compare traces only when they use the same throttling setting.
- Anonymous functions. Arrow functions can appear as
(anonymous). Click the bar and read the source location, or give the function a name while you investigate. - Red corners on tasks. A red marker on a Task bar flags a long task. The next chapter covers these.
Exercise
In the flame chart, a refreshView bar is 60 ms wide. Directly under it, a bar for ReportComponent template execution is 58 ms wide, and under that a score bar is 56 ms wide with nothing beneath it. Which function should you investigate first, and why? Which tab would you use to find out how many times it ran?
Show answer
Investigate score. It is the leaf with the largest self time (about 56 ms), while refreshView and the template function mostly pass time down to their children. Use the Call Tree tab, which lists the number of calls and the self and total time per function. Bottom-Up also shows aggregate self time.