Skip to content
About
Main content

Differential profiling

How does diffing against a matched control show the cost neither profile shows alone?

You have shown that A and B differ (Statistical hygiene). The differential profile tells you where.

Comparing two by eye fails, because both are dominated by the frames that are large in both. A colors each frame by the change in its width. It surfaces the frames that moved, often narrow ones that you cannot see in either graph alone.

Three conditions make the diff valid. If you break any of them, you get confident nonsense:

  1. Identical load. Both profiles must be taken under the same load. Otherwise the diff measures the load difference.
  2. Enough samples. The change must exceed the noise of each frame. This is the noise-floor requirement from Statistical hygiene, applied to each frame, and it is stricter than at the level of the whole total.
  3. Comparable stack shapes. This breaks when inlining (the compiler copying a small function into its caller) changes between versions. The same work then appears under a different frame, and the diff shows a large decrease in one place and a large increase in another.

The idea worth carrying forward: differential methods are strictly more sensitive than absolute ones, at the price of needing a valid control. It is the same reason the paired, interleaved design of Statistical hygiene beats an unpaired comparison, and the same reason set . Comparison against a matched baseline removes the that both sides share. The discipline lies in making sure the baseline is really matched.


What this article forbids

  • Using on-CPU profiling as the first step, without the wall-minus-CPU check.
  • Reading flamegraph width as self time.
  • Believing a frame that is supported by only a handful of samples.
  • Treating an instrumented binary as representative of the deployed one.
  • Concluding "CPU-bound" from high CPU without looking at .
  • Declaring a resource healthy on utilization alone.
  • Adding per-operator times and calling the sum a partition of .
  • Diffing profiles that were taken under different load.

Escapes and their prices

EscapeWhat it buysWhat it costs
SamplingUniform, bounded overheadA resolution floor: events shorter than the sampling interval effectively do not exist
ExactnessOverhead proportional to event rate, uneven, which distorts the hot paths it measures
Adaptive or tail-triggered tracingVisibility of rare eventsA sample that is no longer representative
The only view of why a cycle stalledMultiplexing extrapolation, and often unavailable on shared hardware
Engine-level operator profilesThe correct attribution axisTrust in the engine's own accounting, which is also instrumentation, with its own overhead and blind spots

One principle