research30 min studyLesson 986 in Engineering

Performance counterfactuals and mechanism tests

Test why an improvement occurs with explicit interventions, predicted mediators, and alternatives to a favorable profile.

On this page

What you’ll understand

  • Distinguish observed time share from the effect of making code faster.
  • State assumptions behind a performance counterfactual and a causal contrast.
  • Design mechanism tests that can distinguish competing execution explanations.

A profile showing where time is spent does not by itself show what would happen if that code became faster. Parallel dependencies, locks, and overlap can make a busy function irrelevant to completion time, while a short critical section controls overall progress. A mechanism claim therefore needs an intervention and a predicted response. Treat counters and traces as evidence about a proposed explanation, then test alternatives rather than naming a bottleneck from one colorful chart.

Predict the effect of a specific intervention

Define what the proposed change preserves and what it alters: bytes transferred, instruction count, synchronization, scheduling, numerical accuracy, or offered load. A counterfactual such as halving a serial component’s duration is different from deleting its work. Under a fixed serial decomposition, Amdahl-style accounting predicts a maximum gain from accelerating that component while everything else remains unchanged. That model can guide a test, but it becomes inappropriate when the intervention also changes overlap, queueing, cache behavior, or the amount of work.

Compare the predicted mechanism with observable mediators at compatible boundaries. A compression hypothesis may predict fewer network bytes and more CPU work; an allocator hypothesis may predict fewer contended acquisitions without changing application output. Measure whole-operation completion as well as the mediator, since expensive work can move outside an instrumented region. A predicted mediator changing in the expected direction is corroboration, not proof that no other path caused the outcome. Include controls for instrumentation overhead and changed execution scheduling.

Tnew=Told[(1−f)+fs],S=1(1−f)+f/sT_{\rm new}=T_{\rm old}\left[(1-f)+\frac{f}{s}\right],\qquad S=\frac1{(1-f)+f/s}
T is seconds, f is the fraction of baseline time in a non-overlapping serial component, and s≥1 is its local speedup. The formula assumes fixed work and unchanged remaining time; it is not a general decomposition of parallel critical paths or queues.↔ Scroll wide equations horizontally.

Make causal assumptions explicit

Let each experimental unit have potential outcomes under an implemented control and treatment. With the same nonzero treatment probability strictly below one for every unit, randomized assignment can make observed groups comparable in expectation within the chosen population when consistency, suitable independence, and absence of relevant interference or carryover hold. Blocking can improve precision while preserving the assignment rule. If assignment probabilities differ across blocks, combine within-block contrasts with target-population weights rather than blindly using an unweighted group difference. A before-and-after deployment without comparable load may instead combine treatment with a workload shift. Clearly identify which changes were randomized and which assumptions connect measured differences to the desired causal effect.

Coz provides an original example of an intervention-based performance tool: it estimates virtual speedup effects using controlled delays of other concurrent execution, under its mechanism and measurement assumptions. That is more specific than reading ordinary profiler time shares. It does not imply every delay experiment reproduces every real optimization, or that a real code change preserves the same scheduling and resource effects. Validate a promising intervention with the actual implementation and compare its end-to-end result to the predicted response.

τ=E[Y(1)−Y(0)],τ^=YˉZ=1−YˉZ=0\tau=\mathbb E[Y(1)-Y(0)],\qquad \widehat\tau=\bar Y_{Z=1}-\bar Y_{Z=0}
Y is the declared outcome, such as milliseconds per independent run; Z is randomized assignment with a common probability strictly between zero and one across target units. The difference estimates the population contrast under the stated consistency and interference assumptions; unequal block probabilities require appropriate adjustment. A formula alone supplies no identification guarantee for an observational comparison.↔ Scroll wide equations horizontally.

Design tests where alternative explanations diverge

If a speedup is attributed to memory traffic, vary problem size across a cache boundary, keep outputs fixed, and check the expected traffic response. If synchronization is blamed, vary contention independently where feasible and predict when the benefit should disappear. Include a negative control that should not respond to the proposed mechanism, while considering whether it changes other resources. Counterexamples narrow the explanation. A mechanism supported at one size, topology, and load should not be generalized to all executions without new evidence.

The roofline instrument permits a bounded counterfactual inside its fixed model. Reset, set both I=2 and B=100, predict a 200 GFLOP/s ceiling, then Play or Step. Separately Reset, set both I=2 and B=200, predict 400 GFLOP/s, then Play or Step. Declare I at the main-memory transfer boundary and retain the synthetic compute ceiling of 1000 GFLOP/s. These are model ceilings, not measured throughput or a causal profiler. Doubling B in this model cannot establish that a physical application will receive twice the usable bandwidth or complete twice as fast.

A local optimization predicts a bounded whole-operation gain

A fixed serial job takes 100 s. A non-overlapping component accounts for 40% of that time and is accelerated by a factor of two without changing other work. Compute the predicted total, then compare with a separately measured optimized total of 95 s.

  1. The original component takes 40 s and the remaining work takes 60 s. Halving the component gives 20 s while the stated model keeps the other 60 s unchanged.

  2. The model predicts 60+20=80 s and a whole-job speedup of 100/80=1.25. It does not predict a twofold whole-job gain.

  3. The observed 95 s is 15 s above the model prediction. Investigate whether the measured component accelerated as assumed, whether other work changed, and whether the serial decomposition was valid. The gap alone cannot identify which assumption failed.

The result

A numerical counterfactual becomes a mechanism test when its assumptions and predicted deviations are checked against actual execution.

Explore the model

Interactive lab

Interactive lab · roofline

Separate a fixed-model counterfactual from a measured intervention

At the main-memory boundary: Reset, set both I=2 and B=100, predict a 200 GFLOP/s ceiling, then Play or Step. Separately Reset, set both I=2 and B=200, predict 400, then Play or Step. The fixed 1000 GFLOP/s synthetic ceiling is neither a causal profiler nor a hardware throughput guarantee.

Separate a fixed-model counterfactual from a measured interventionSynthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Current readings: Attainable ceiling: 640 GFLOP/s; Ridge intensity: 12.5 FLOP/byte; Ceiling regime: Memory-bound ceiling. All parameters are adjustable with the labeled controls below.Hypothetical roofline upper bound: 640 GFLOP per second at operational intensity 8 FLOP per byte and bandwidth 80 gigabytes per second.0.1110641101001000Operational intensity · FLOP/byte · log scaleCeiling · GFLOP/s · log scalePeak: 1000
Attainable ceiling / kernelBandwidth roof / traceCompute ceiling
Attainable ceiling
640 GFLOP/s
Ridge intensity
12.5 FLOP/byte
Ceiling regime
Memory-bound ceiling
t = 0 s

Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA model prediction suggests an experiment; it does not replace its identification assumptions.

Check your understanding

Why does a function consuming 40% of observed time not automatically promise a 40% whole-system improvement when optimized?

Try it yourself

Under the same fixed serial accounting, a component is 20% of a 100 s job and becomes four times faster. Compute the new total and whole-job speedup.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

The unchanged 80 s remains; only the 20 s component is divided by four.

Compare with the solution

The new total is 80+20/4=85 s. The speedup is 100/85≈1.1765, corresponding to a 15% time reduction. This conclusion assumes unchanged work and a non-overlapping serial decomposition; a parallel profile with 20% sampled activity does not automatically satisfy those conditions.

Take it with you

  • Observed time shares and intervention effects are different quantities.
  • Use explicit counterfactual assumptions and mechanism-specific predictions.
  • Randomization and valid controls support causal interpretation within a stated domain.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.