Definition
Causal attribution is the claim that one change, the intervention, produced an observed difference in a measurement through a stated mechanism. An intervention is a change made on purpose while other conditions are held fixed, such as switching on a cache, a store of earlier results that lets repeated work be skipped. A competing explanation is any other change that could have produced the same difference, such as a new compiler setting. Attribution is justified only when the comparison rules out the competing explanations and the mechanism’s predictions hold.
Where it fits
Main entry: Causal inference (§11.11).
The causal inference entry defines an effect as the difference between the outcome under the intervention and the outcome that the same things studied, such as the same devices, would have shown without it. It also treats confounding §11.10: a third factor that changes together with the intervention and also affects the outcome. Performance experiments have an advantage that many sciences lack. The experimenter can usually set the intervention directly, run both conditions on the same device, and use randomization §11.8, a random order of the runs, so that a slow drift such as warming affects both conditions alike. This entry shows how to turn an explanation into predictions that such an experiment can contradict.
In an invented case, a latency plot becomes lower and flatter after a cache is added to a lookup that searches a table of records. The proposed explanation is that cache hits, lookups whose answer is already in the cache, skip the search. Several other things changed at the same time and are competing explanations: the new build used different compiler settings, the device’s storage was in a different state, radio scheduling differed, or all cached runs came after all uncached runs, when the device had warmed up.
A mechanism makes numerical predictions. In an invented cost model, an uncached lookup examines records at 1 work unit each and does 2 units of fixed work, so it costs units: 3, 6 and 10 units for , 4 and 8. A cache hit replaces the search with a 1-unit check and costs units whatever is. Let be the hit rate, the fraction of lookups that are hits, and let a miss cost as much as an uncached lookup, ignoring its 1-unit check. The average cost is then ; for and it is units. The model predicts three things that the competing explanations do not.
Without the cache, the cost grows by 1 unit for every added record; with the cache and a high hit rate, it barely grows.
The saving shrinks as the hit rate falls, and it vanishes at .
A count of records examined, taken independently of the timing, falls from per lookup to , which is in the example.
An observation falsifies the explanation when the explanation says that the observation cannot happen. Four such observations are: requests counted as hits still examine all records while latency improved; the same build with only the cache switched off, run in random order with the cached runs on the same device, is just as fast; forcing every lookup to miss leaves the improvement in place; and uncached latency does not grow with . Forcing every lookup to miss is a negative control §10.29, a condition in which the mechanism predicts no effect. Writing the predictions down before the runs, a practice called preregistration §13.17, keeps contrary results from being explained away afterwards.
A test counts only if it could have shown the predicted difference. A switch that leaves the cache running, or a timer placed around a code path that the cache does not serve, cannot show the difference, and its null result refutes nothing. A hit counter that reads zero with the cache off and well above zero with it on confirms that the switch works. The measurement must also resolve the prediction. At the model predicts a saving of units; at an invented 1 microsecond per unit, that is 7 microseconds. A timer that ticks every 30.5 microseconds, the tick of a 32,768-hertz clock, cannot resolve one such difference, because every reading is a whole number of ticks; the counter quantization §11.35 entry treats this effect. Timing 1000 lookups together turns the difference into 7 milliseconds, about 229 ticks, which the timer resolves easily. A positive control §10.30, a deliberately inserted delay of known size, shows that the measurement detects a difference of that size.
Limits and common mistakes
A performance curve alone rarely identifies a unique cause. Several mechanisms can predict the same curve, and a competing explanation that makes the same predictions stays possible until some test separates the two.
A difference that appeared when the cache was added is only an association until the comparison rules out everything else that changed in the same build.
Selection changes the comparison. Keeping only successful runs, or only runs after start-up, in one condition and not in the other creates a difference that the cache did not cause. Both conditions must be filtered by the same rule, fixed before the results are seen.
Agreement with the predictions supports the mechanism but does not prove it. Changing the explanation after each contrary result until it fits makes the explanation impossible to falsify, and then it explains nothing.
Questions answered
What would falsify the cache explanation?
The cache explanation, the claim that adding a cache made lookups faster because cache hits skip a repeated search through the stored records, is falsified by any observation that it says cannot happen. Four such observations are:
a trace (a record of which code ran), taken independently of the timing, shows that requests counted as cache hits still search all records, while latency still improved;
the same build with only the cache switched off, run in random order with the cached runs on the same device, is just as fast;
forcing every lookup to miss the cache leaves the improvement in place;
latency without the cache does not grow with the number of records, so the search was never the cost the cache removed.
Each test counts only if it could have shown the difference. The switch must really disable the cache, which a hit counter of zero confirms, and the measurement must resolve the predicted difference, for example by timing many lookups together when one lookup’s saving is smaller than one tick of the clock. A null result from a test that misses the cached path, or that cannot resolve the difference, refutes nothing. The predictions should be written down before the runs, and contrary results kept rather than explained away.
Related entries: Memoization and caching (§14.20), Confounding (§11.10), Empirical cumulative distribution function (ECDF) (§11.17), Negative control (§10.29), Counter quantization (§11.35).