Performance Engineering · Optimization Practice
Recognizing the Point Where Further Optimization Stops Paying
When remaining candidates fall inside the measurement noise floor or the untouchable remainder dominates, the correct action changes from optimizing to sizing or redesigning.
A system that has been optimized for a while reaches a state that looks like failure and is not: every remaining candidate is small, every measurement is ambiguous, and the effort per unit of improvement has grown by an order of magnitude. Continuing from that state is usually a mistake, and so is stopping without diagnosing why the returns fell. The state has three distinguishable causes, and they call for three different responses.
Returns fall for a reason that can be named
The first cause is arithmetic. The remaining fractions are small, so even a large local factor yields an overall change below the noise. With Pareto’s form of the ceiling, the largest remaining fraction being under five percent means no single change can exceed five percent, and the realistic change is a fraction of that.
The second cause is that the remaining cost is irreducible in the code being measured. The work is a system call, a network round trip, a disk seek, a memory access at DRAM latency, a queueing delay. Optimizing the instructions around it changes nothing, because the instructions were never the cost. This is where a profile’s self-time and the actual resource accounting diverge, and where the honest statement is that the remaining time is spent waiting on something with its own performance characteristics.
The third cause is that the remaining cost is structural: the design produces the work, and no local change can stop producing it. A design that makes six sequential round trips per request has a floor of six round trips; making each round trip ten percent cheaper does not change the floor. The only change that addresses the floor is one that changes the number of trips, which is a redesign and is a different kind of decision with a different kind of cost.
The distinction matters because the three causes have different appropriate responses. The first calls for stopping. The second calls for measuring the resource, not the code. The third calls for evaluating a redesign against its cost.
Measuring the noise floor, and the rule it imposes
Every measurement has a distribution, and an optimization is only detectable if its effect exceeds the spread of repeated identical runs. The spread comes from scheduling, from memory layout and allocator state, from cache and branch predictor state, from neighbours on shared hardware, and from the workload’s own arrival variability.
A noise floor is established by running the identical workload several times without any change and measuring the spread of the target metric. That spread defines two quantities: the resolution of any single comparison, and the size below which a difference is not attributable to the change.
import statistics
def resolve(new_runs, baseline_runs, z=1.96):
"""Smallest difference distinguishable from run-to-run noise."""
nb, nn = len(baseline_runs), len(new_runs)
se = statistics.stdev(baseline_runs) / nb**0.5
se_new = statistics.stdev(new_runs) / nn**0.5
pooled = (se**2 + se_new**2) ** 0.5
return z * pooled
A useful rule follows: when the expected saving for every remaining candidate is below the resolution of the measurement available, the candidate list has stopped being actionable. Not because the savings are unreal but because the process cannot distinguish a success from a null result, and a process that cannot distinguish outcomes cannot be steered. Effort spent there produces changes that are adopted on faith and defended by argument.
The rule has a counterpart at the other end: resolution can sometimes be bought. A longer run, more repetitions, a quieter machine, or a workload amplified to make the target the dominant cost can all push the resolution below the effect size. The decision to buy resolution is itself an optimization decision with a payoff, and it is only worth making for at least one candidate whose expected saving exceeds the cost of the measurement work.
The untouchable remainder and what it means
When the profile shows a distribution of cost across many small entries with no single dominant one, the ceiling analysis has effectively collapsed: no candidate has a fraction large enough to move the total, and the sum of all remaining candidates is itself split among changes that interact.
This is the signature of a design whose cost is distributed rather than concentrated. It appears in systems that perform a long sequence of small operations — a per-field accessor over a structure that traverses several layers, a request path that touches dozens of small services, a rendering pipeline that adds many small contributions per frame. Each contribution is cheap and necessary; the total is not.
Two moves remain, and neither is a local optimization.
The first is to accept the total and change the resources: more machines, a faster tier, better data locality that raises the effective speed of the many small accesses at once. This is sizing, not optimizing, and it answers a different question. It is not a defeat; it is frequently the correct answer for a system whose cost is spread, because the cost of the redesign exceeds the cost of the hardware for the remaining life of the system.
The second is to attack the sequence. If the cost is a hundred small operations per unit of work, then reducing the sequence length by a factor of four is the only change with a large payoff, and it is achieved by changing the shape of the computation: batching the operations, moving the loop inside the layer, replacing the traversal with a different data layout, or eliminating layers. Each of these is a redesign with a large blast radius, and it must be justified against the full saving, not against a local factor, since it is the only remaining candidate of consequence. The removal question applies at this scale: the sequence is work, and the cheapest sequence is the one that is not performed.
The cost that is not in the profile
Optimization effort has a cost, and it is not measured by the profiler. The relevant costs are the ones the effort forecloses: capacity for features, the maintenance of specialized code paths, the attention of the people who understand the system, the risk introduced by each change to a working system.
This is not an argument against optimizing; it is an argument for pricing the effort in the same units as the saving. A week of work that yields a two percent improvement in one metric, on a system where the metric is not the constraint, has a negative return even if the change is technically sound. The expected-payoff framing in the ranking discussion prices this by dividing by effort; the plateau is what it looks like when the division has been applied to everything and nothing clears the bar.
The complementary cost is the one paid for having optimized too narrowly. A system tuned to one workload’s distribution becomes brittle to a change in that distribution: the fast path is fast because the input has a particular shape, and a shift in the shape moves all the traffic to the slow path. The cost-shifting analysis names the destination of each relocation, and brittleness to a workload change is the destination that is hardest to price because it appears as an unrelated incident later.
What the stopping decision actually consists of
The decision to stop is not a decision to do nothing. It is a decision to change the type of intervention, and it has a short checklist.
Confirm the noise floor and confirm that the remaining candidate list is below it. If it is not, the plateau has not been reached and the analysis is wrong.
Classify the remaining cost: arithmetic residue, irreducible resource waiting, or structural sequence. The classification determines whether the next move is a resource measurement, a sizing decision, or a redesign proposal.
State the constraint the system is actually under. A plateau in latency is not a plateau in cost, and a system that has stopped getting faster may still be worth making cheaper or more predictable. The objective chosen in the workload-mix discussion determines which plateau has been reached, and it is entirely possible to be at the end of the latency curve while the throughput curve is untouched.
Record the frontier. The configuration frontier is the durable output of the whole exercise: it states what the system can do under different trade-offs, and it is what makes the stopping decision revisitable when the workload changes. A plateau without a recorded frontier is indistinguishable from an unfinished optimization, and will be re-litigated by the next person who sees the profile.
The stopping condition is therefore not “the profile is flat” but “the remaining candidates are below the resolution of the measurements that can justify their work, and the remaining cost is of a kind that local changes cannot address.” At that point further work on the same axis has no expected value, and the effort belongs somewhere else — on the resource that the remainder is actually waiting for, on a design whose sequence length is the floor, or on a different metric entirely.
References
- The Art of Computer Systems Performance Analysis — Raj Jain, Wiley
- No Silver Bullet — Essence and Accident in Software Engineering — Frederick P. Brooks Jr., Information Processing 86 (IFIP), 1986
- Computer Architecture: A Quantitative Approach — Hennessy and Patterson, Morgan Kaufmann
- Designing Data-Intensive Applications — Martin Kleppmann, O'Reilly Media