What happens when I press enter?
Every request runs in two phases. The model reads your whole prompt in one go, then writes the answer one token at a time. The two phases hit different limits in your hardware, which is why a machine can be quick at one and slow at the other.
Two phases with different bottlenecks
Prefill: reading the prompt
Prefill is the reading phase. The runtimeRuntimeThe software that loads a model file and runs it.Read more turns your prompt into tokensTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more and pushes all of them through the model together. The chip does a huge amount of maths in parallel, so the limit is raw compute.
Prefill is fast per token. A GPU reads a long prompt many times faster than it can write. But the work grows with the prompt, so pasting in a 30-page document means a real wait before anything happens.
Decode: writing the answer
Decode is the writing phase. The model produces one token, adds it to the text, and runs again for the next one. Each step needs every weight in the model, read out of memory, to make a single token.
That makes decode limited by memory bandwidthMemory bandwidthHow fast data moves out of memory, in GB per second. It sets decode speed.Read more, the speed at which weightsWeightsThe full set of a model's parameters, stored in a file.Read more move from memory to the chip. The maths per token is small. Fetching the weights is the slow part. What makes a model fast? turns this into a formula.
Prefill
Reads all prompt tokens at once. Limited by compute, so it is slow when the prompt is long.Decode
Writes the answer one token at a time. Limited by memory bandwidth, so it is slow when the model is big.Time to first token versus tokens per second
Two numbers describe how a request feels. Time to first token, or TTFT, is how long you wait before the first word appears. That is mostly prefill.
Tokens per second, written tok/s, is how fast the words stream after that. That is decode.
For a short chat message, TTFT is a fraction of a second and only tok/s matters. For a coding agent that sends 20,000 tokens of files with every request, TTFT can be the larger wait. A machine with high bandwidth and modest compute writes quickly but makes you wait at the start.
Short prompts and long answers depend on bandwidth. Long prompts and short answers depend on compute. Know which kind of work you do before you buy hardware.
The KV cache
While reading, the model computes two sets of numbers for every token, called keys and values. Later tokens look back at them to decide what matters. The runtime keeps them in memory in the KV cache, so it never computes them twice.
This is why the second message in a chat starts faster than the first. The cache already holds your earlier conversation. The runtime only has to prefill the new message, then carry on writing.
The cache is not free. It grows with every token in the conversation and takes memory alongside the model itself. How much can the model keep in mind? covers how big it gets and Will the model fit in my memory? covers how to budget for it.
The cache only helps when the start of the prompt stays the same. If an app edits an early part of the conversation, such as a system promptSystem promptStanding instructions placed before the conversation.Read more that changes every turn, the runtime throws the cache away and reads everything again. Some agent tools do this and feel slow for that reason.
A timeline of one request
Here is one chat message from the moment you press enter.
- 1Tokenize the prompt
- 2Prefill: read all tokens, fill the KV cache
- 3First token appears
- 4Decode: one token per pass
- 5Stop token, answer ends
On a typical laptop with a small model, steps 1 to 3 take well under a second for a short message. Step 4 then runs at the machine's decode speed until the model emits a stop token or hits a length limit.
Start a model in Ollama with timing turned on. First paste a long document and ask for a one-line summary. Then ask a one-line question that needs a long answer.
ollama run qwen3:8b --verboseCompare prompt eval rate with eval rate. The first is prefill speed, the second is decode speed.
Go deeperThat's enough
Why decode cannot run in parallel
Each new token depends on the one before it. The model cannot start token 51 until it knows token 50. So decode is a strict loop of one pass per token, and the full weights are read once per pass.
Prefill has no such chain. All prompt tokens are known up front, so the chip processes them together and reuses each weight it fetches across hundreds of tokens. That reuse is what moves the bottleneck from bandwidth to compute.
Prefill gets slower as context grows
Each token in the prompt looks back at every token before it. Doubling the prompt more than doubles the attention work, so very long prompts slow down towards the end. Newer models use tricks such as sliding-window attention to soften this, but long prefill is still the main cost of large contexts.
Prompt caching across requests
Runtimes such as llama.cpp and vLLM can keep the KV cache for a shared prefix between separate requests. If every request starts with the same long system prompt, only the first one pays for it. This matters most when several people share one server, covered in What changes when many people use one model?.
Speculative decoding
A small draft model guesses the next few tokens, and the big model checks them all in one pass. Checking is a prefill-style job, so it is cheap. When the guesses are right, you get several tokens for the price of one pass. How do I make it faster? covers when it helps.