youssefsabri
← index · · 1 min read #perf#notes

The flamegraph is lying to you about width

Width is not work. A short note on self time.

A wide frame means the function was on the stack a lot. It does not mean it was doing work. I have optimised the wrong one more than once.

Width is total time — the frame plus everything it called. What belongs to the function itself is the strip not covered by its children: self time. A frame taking 60% of the graph with one child covering 59% is a pass-through.

So, in order:

  1. Sort by self time, not width.
  2. Find the widest frame whose children are narrow. That is the real leaf cost.
  3. Only then look at call counts.

Rule two is the one worth keeping: you want the deepest wide frame, not the first one you notice.

end 2026.08.14
← back to index
normal ~/posts/reading-a-flamegraph --:--:--