Decompose before optimising
- : time to first token, which is prefill.
- : time per output token, which is decode.
- : the number of tokens generated.
Each term has a different fix, and optimising the wrong one is the usual reason a week of work changes nothing.
For most model applications that last term dominates everything else, which means the shortest path to lower latency is generating fewer tokens.
Attack the output length first
Asking for a summary in three sentences rather than a page halves the latency directly, at no engineering cost.
Removing explanation the caller does not read is the same saving. So is stopping at a stop sequence rather than letting the model run to its limit.
Streaming does not reduce at all. It changes the perceived latency to , which is usually the more valuable number.
Then the queue, then the model
Queue time is invisible in a single-request benchmark and is often the largest term under load, so it has to be measured in production rather than on a laptop.
Decode is memory-bound, so a smaller or quantised model is faster almost in proportion to its size, while a faster chip with the same bandwidth is not.
That is why quantisation is the most reliable single change for generation speed, and why it does far less for prefill.
One optimisation, in order
- Measure the four terms separately, at the percentiles users feel.
- Cut the output length and the prompt length, in that order.
- Stream, so the first token arrives while the rest is produced.
- Cache whatever repeats, including the system prompt through prompt caching.
- Only then change the model, the hardware or the serving stack.
The structural wins
Independent calls should run concurrently. A pipeline that retrieves, reranks and classifies in sequence when two of those do not depend on each other is paying twice.
A small model drafts several tokens and the large one verifies them in a single pass, which raises the tokens produced per weight read.
Sending easy requests to a small model and hard ones to a large model lowers the average without lowering the ceiling, and the classifier that decides is usually cheap.
Percentiles are the last point and the most commonly missed. An average of 800 ms with a p99 of 12 seconds is a system that feels broken to one user in a hundred, every day.