deep · 5 min
Prefill and decode
The two stages of a call: read the whole prompt at once, then write one token at a time.
updated 23 Sept 2026
Let's time one request. We send a 2,000-token prompt and get back a 500-token answer. Say the first word of the answer shows up after half a second. Then the rest trickles out, a token every 20 milliseconds or so, for about ten more seconds. (These are made-up numbers, but realistic ones.)
So the model read 2,000 tokens in half a second, and then took twenty times as long to write a quarter as many. Why is writing so much slower than reading?
Two stages
Every call to a model has two stages.
The first is prefill. The model takes all 2,000 prompt tokens and runs them through the network together, in parallel. On the way it works out the in-between results for every prompt token that later steps will need, and at the end it has the first output token.
The second is decode. Now the model writes the other 499 tokens, one at a time. Each token needs its own pass through the network, and each pass has to wait for the one before it. Token 300 can't be written before token 299 exists. This is the next-token prediction loop: add the new token to the text, run again.
The network is the same in both stages (the stack of layers in transformer). What changes is how much work each pass gets to do at once. The prompt goes in as one big batch of work. The answer comes out as 499 small steps in a row.
That's why speed gets measured with two numbers. Time to first token (TTFT) is how long until the answer starts, and it's mostly prefill. Time per output token (TPOT) is how long each one after that takes, and it's decode. Put together:
For us that's 0.5 s + 499 × 0.02 s, about 10.5 seconds. Prefill is a sliver of it. The answer's length is most of it. (Flip TPOT over to get the speed a user sees: 100 ms per token is 10 tokens a second.)
Why decode is the slow one
Both stages do the same kind of maths. The difference is how much maths they get out of each trip to memory.
A GPU has two limits: how fast it can calculate, and how fast it can read from its memory. The model's weights live in that memory, and every pass through the network has to read all of them.
In prefill, one read of the weights gets used for thousands of tokens at once. The GPU does plenty of maths for every byte it reads, and runs near its full calculating speed. We call that compute-bound.
In decode, one read of the weights makes one token. The GPU finishes the maths quickly and then sits waiting for more data from memory. Its speed is set by how fast weights can be moved, not how fast it can calculate. That's memory-bound.
Let's put numbers on it, using an older GPU, the NVIDIA A10. It can do 125 trillion operations a second and read 600 GB a second from memory. Divide one by the other: about 208 operations for every byte it reads. Decode on Llama 2 7B only asks for about 62.
So most of the calculating power sits idle during decode. You can even estimate decode speed from memory alone. A 7-billion-parameter model at 2 bytes per number is 14 GB of weights. Reading 14 GB at 600 GB a second takes about 23 ms. That's roughly the fastest one token can come out on an A10, however little maths it needs. Faster decode mostly means more memory bandwidth.
So input tokens are cheap?
In time, compared to output, yes. In one set of measurements, adding 512 tokens to the prompt added less delay than writing 8 more tokens of output. That gap is part of why providers charge differently for input and output (token pricing).
But "long prompts are free" goes too far. Prefill still has to process every one of them, so a very long prompt does push up time to first token.
Keeping the GPU busy
One request in decode leaves most of the GPU idle. So servers batch: they run many users' requests through the same pass, and one read of the weights serves many tokens. Total throughput goes up, but each request gets a bit slower. In one measurement, a batch of 64 gave 14 times the throughput at 4 times the delay per request. That's also why the same request won't always take the same time on a shared server.
Decode also doesn't redo the prompt's work at every step. The in-between results from prefill are kept and reused, which is the KV cache. Those stored results have to be read from memory for every new token too, which adds to decode's memory load.
Running both stages on the same GPUs has a cost: they get in each other's way. A new user's long prompt can hold up the tokens everyone else is waiting on. Serving systems have gone two opposite ways on this. Some split the stages onto different machines, each sized for its job. Splitwise (Microsoft, 2023) found decode doesn't need the newest GPUs' calculating power and got 1.4 times the throughput at 20% lower cost. Others keep them together but chop each prompt into chunks that fit around the decode steps, so decode never stalls; Sarathi-Serve (2024) reported 2.6 to 5.6 times more serving capacity that way. As an API user you don't pick. But it's why a provider's time to first token and tokens per second can move separately.
Back to our request
The GPUs and models here are from 2023 to 2025 and a few generations old. Newer GPUs have more bandwidth (an H100 has 2.15 times an A100's), so the milliseconds have moved. The shape hasn't. Prefill is parallel and compute-bound, decode is one step at a time and memory-bound.
So if our 10.5-second request feels too slow, where do we push? Cutting the prompt in half would shave a little off the half second before the first token. Cutting the answer in half would save about five seconds. And if the answer really does need to be long, we can at least show it as it's written, which is what streaming is for. Users then wait half a second for something to read, not ten.
Further reading
- LLM Inference Performance Engineering: Best Practices, Databricks, 2023. The clearest intro. TTFT, TPOT and the latency formula come from here, along with the 512-versus-8 comparison.
- A guide to LLM inference and performance, Baseten, 2025. Works through the A10 arithmetic step by step, if you want to redo it for your own GPU.
- Mastering LLM Techniques: Inference Optimization, NVIDIA, 2023. Prefill and decode from the GPU's side, plus batching.
- Splitwise: Efficient generative LLM inference using phase splitting, Patel et al. (Microsoft), 2023. The case for running the two stages on different hardware.
- DistServe, Zhong et al., 2024. Splits the stages across GPUs too, and ties TTFT to prefill and TPOT to decode.
- Sarathi-Serve, Agrawal et al., 2024. The other way: keep the stages together and chunk the prompt.