7 min readperformanceprofiling
Reading a flamegraph like a map
Width is cost and depth is structure. Once you stop reading a flamegraph top-to-bottom it stops looking like noise.
The first flamegraph anyone looks at is unreadable, because the instinct is to read it like a stack trace — top to bottom, looking for the culprit. It is not a trace. It is a map, and maps are read by area.
Width is cost
Horizontal span is time spent, aggregated. A frame that takes half the width took half the samples, no matter how shallow it looks or how boring its name is. Start at the widest thing you do not recognise.
Depth is structure
Vertical depth tells you how the work is organised, not how expensive it is. A deep, narrow tower is a call chain you can safely ignore. A wide, flat plateau is a hot loop with no abstraction left to blame.
Plateaus are where the answers are
The shapes worth investigating are the ones with a flat top: a single frame holding a lot of width with nothing meaningful above it. That is code doing actual work, and it is usually either serialisation, allocation, or a lock.
Compare, do not admire
One flamegraph tells you where time goes. Two flamegraphs — before and after, or healthy and degraded — tell you what changed, which is nearly always the question you actually had.