Back to Blog
October 25, 2026

The short version: prefill is the first phase of an LLM request. The model reads every prompt token in one parallel pass, builds the KV cache, and emits the first output token, so prefill sets time to first token (TTFT). Decode is the second phase. The model then makes one token per step for each request, so decode sets the time per output token, also called inter-token latency (ITL). Prefill keeps the GPU's compute units busy. Decode mostly waits on memory, which is why the two phases fight when they share a GPU.

What happens during prefill?

The engine takes the whole prompt and runs it through the model at once. All prompt tokens go through each layer together as one large matrix multiply. The attention keys and values for every prompt token go into the KV cache, and the last position gives the first output token.

Because the work is one big parallel batch, prefill uses the GPU well. The Sarathi-Serve paper puts it this way: "Prefill iterations have high latency but saturate GPU compute due to parallel processing of the input prompt." The Splitwise paper calls this phase "a compute-intensive prompt computation." Prefill time grows with prompt length, so a long prompt means a long wait before the first token appears.

What happens during decode?

After the first token, the model generates the rest one at a time. Each step takes the newest token, attends to everything already in the KV cache, appends one new key and value per layer, and makes the next token. A step cannot start until the step before it is done, because it needs that token as input.

Each step does little arithmetic for each request, but it still has to stream all the model weights and that request's KV cache out of GPU memory. Sarathi-Serve says decode iterations "have low latency but also low compute utilization" because "a decode iteration processes only a single token per request." Splitwise calls token generation "memory-intensive" and says it "underutilizes compute resources."

Rough arithmetic shows why. An 8B-parameter model at BF16 has about 16 GB of weights. A matrix multiply does about two floating-point operations per weight per token. With one decode token in the batch, that is about one operation per byte of weights read, which is far too little to keep the compute units busy. With a 4,000-token prefill, the same weights are read once and used 4,000 times. That ratio is the core of the difference.

Why does batching help decode much more than prefill?

Batching lets many requests share one read of the weights. For decode, this is close to free throughput: 64 requests decoding together read the weights once per step instead of 64 times. Sarathi-Serve notes that low per-step utilization "makes batching highly effective for decodes." Prefill already fills the compute units, so adding more prefill tokens to a batch mostly makes the step longer.

Decode batch size has a ceiling, and that ceiling is KV cache memory. Each running request holds its own cache, and the cache grows with every token. The PagedAttention paper describes KV cache memory per request as "huge" and says it "grows and shrinks dynamically." It also says that wasted cache memory limits batch size, and paging the cache let vLLM improve throughput by 2 to 4 times over earlier systems. Our post on KV cache VRAM for a 128K context gives the memory formula and worked numbers.

How do serving engines stop prefill from stalling decode?

When one GPU serves many users, a long new prompt can block every request that is already decoding. Each decode step has to wait while the big prefill runs, so ITL spikes for everyone. There are two main fixes.

  • Chunked prefill. Sarathi-Serve splits a prefill "into near equal sized chunks" and mixes them into batches "without pausing ongoing decodes." It reports 2.6x higher serving capacity than vLLM for Mistral-7B on one A100, under tail latency limits. In vLLM V1, the optimization docs say chunked prefill "is enabled by default whenever possible." The scheduler batches all pending decodes first and then fills the rest of the max_num_batched_tokens budget with prefill chunks. Smaller budgets such as 2048 give better ITL. Larger budgets give better TTFT.
  • Disaggregated prefill. DistServe runs prefill and decode on different GPUs, "hence eliminating prefill-decoding interferences," and then moves the KV cache across. It reports it can "serve 7.4x more requests or 12.6x tighter SLO" than the systems it compared against. Splitwise uses the same split to put decode on cheaper hardware, and it reports 1.4x higher throughput at 20% lower cost. The vLLM disaggregated prefilling docs mark the feature as experimental. They say it lets you tune TTFT and ITL separately and control tail ITL, but that it "DOES NOT improve throughput" in vLLM.

How does an RLM change the prefill and decode balance?

A typical chat request has a modest prompt and a long answer, so decode takes most of the time. An RLM moves most of the work into prefill. In the RLM paper, the input lives in a Python REPL. The root model writes code that slices it and sends pieces to sub-calls through llm_query. The system prompt describes that function as one "that can handle around 500K chars" and suggests "a viable strategy is to feed 10 documents per sub-LLM query."

Here is a worked example with illustrative numbers, not figures from the paper. Say the root splits a 1M-token corpus into 50 chunks of 20,000 tokens. Each sub-call returns a 200-token finding.

  1. Sub-calls. Prefill is 50 x 20,000 = 1,000,000 tokens. Decode is 50 x 200 = 10,000 tokens. That is 100 prefill tokens for each decoded token.
  2. Root loop. Each root turn resends the trajectory so far, so prefill grows every turn, while each turn decodes only a short block of code. The paper notes that only "constant-size" metadata about REPL output goes back into the root history, which keeps that growth in check.
  3. The result. The token count is lopsided toward prefill, and each sub-call pays a full TTFT before its first token. Whether prefill or decode takes more wall time depends on the hardware and batch, because prefill processes tokens in parallel while decode makes them one step at a time. Measure both TTFT and ITL on your own setup.

This shape explains two things. First, it explains the RLM latency numbers. The paper states that "we implemented all sub-LM queries naively as blocking / sequential calls," so every sub-call's prefill adds directly to wall time. It also warns that, without a cap, Qwen3-Coder tried to make a sub-call on everything, "leading to thousands of LM subcalls for basic tasks." Thousands of prefills in a row is a slow trajectory, as our post on whether RLMs are slower than one long-context call shows.

Second, it tells you which optimizations matter. Prefix caching cuts prefill only, so it helps the root loop, where each turn repeats the prefix. It helps sub-calls only when they share a long prefix, as our post on prompt caching for sub-calls covers. Running sub-calls in parallel helps even more on a self-hosted engine, because many short prefills can share batches with chunked prefill. If you serve a sub-call model yourself, tune for TTFT and prefill throughput, not for long-generation ITL.

The bottom line

Prefill reads the prompt in parallel, uses GPU compute well, and sets TTFT. Decode makes one token per step, waits on memory, and sets ITL. Serving engines use chunked prefill or separate prefill and decode GPUs so that the two phases do not stall each other. An RLM sends many large chunks and gets short answers back, so its cost and latency come mostly from prefill. Measure TTFT per sub-call first.

References & Further Reading

  1. Agrawal et al. "Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve." arXiv:2403.02310, 2024. Prefill saturates compute, decode has low utilization, chunked prefills, stall-free scheduling, 2.6x capacity result. arxiv.org/abs/2403.02310
  2. Zhong et al. "DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving." arXiv:2401.09670, 2024. TTFT and TPOT, prefill-decoding interference, 7.4x requests or 12.6x tighter SLO. arxiv.org/abs/2401.09670
  3. Patel et al. "Splitwise: Efficient Generative LLM Inference Using Phase Splitting." arXiv:2311.18677, 2023. Compute-intensive prompt phase, memory-intensive generation phase, 1.4x throughput at 20% lower cost. arxiv.org/abs/2311.18677
  4. Kwon et al. "Efficient Memory Management for Large Language Model Serving with PagedAttention." arXiv:2309.06180, 2023. KV cache size and growth limit batch size; 2-4x throughput. arxiv.org/abs/2309.06180
  5. vLLM project. "Optimization and Tuning: Chunked Prefill." vLLM docs (source on GitHub), accessed 2026-10-25. Chunked prefill on by default in V1, decode-first scheduling, max_num_batched_tokens trade-off. github.com/vllm-project/vllm/blob/main/docs/configuration/optimization.md
  6. vLLM project. "Disaggregated Prefilling (experimental)." vLLM docs (source on GitHub), accessed 2026-10-25. Separate TTFT and ITL tuning, tail ITL control, no throughput gain. github.com/vllm-project/vllm/blob/main/docs/features/disagg_prefill.md
  7. Zhang, Kraska, Khattab. "Recursive Language Models." arXiv:2512.24601, 2025. llm_query sub-calls of around 500K characters, blocking sequential sub-calls, Qwen3-Coder making thousands of sub-calls. arxiv.org/abs/2512.24601
FAQ

Frequently asked questions

Is prefill compute-bound and decode memory-bound?

As a rule of thumb, yes. Prefill multiplies many tokens against each weight it reads, so it fills the GPU's compute units. Decode at small batch sizes reads all the weights for very few tokens, so memory bandwidth limits it. The vLLM docs describe prefill as compute-bound and decode as memory-bound in the same terms.

What are TTFT and ITL?

TTFT is time to first token, the wait from sending a request to getting the first output token. Prefill sets most of it. ITL is inter-token latency, the gap between later tokens, and DistServe calls the same idea time per output token (TPOT). Decode sets it.

Does a longer prompt slow down decode too?

Yes, but less than it slows prefill. Each decode step attends over the whole KV cache, so a longer context means more cache to read each step. A long cache also uses more memory, which leaves room for fewer requests in the decode batch.

Should I turn on disaggregated prefill in vLLM for an RLM?

Probably not as a first step. The vLLM docs mark it as experimental and say it does not improve throughput. Its value is separate control of TTFT and tail ITL. Chunked prefill is already on by default in vLLM V1 and is the simpler lever.

Why is the first token slow but the rest fast?

The first token waits for the full prefill pass over the prompt. Each later token needs only one decode step against the cached keys and values. With a long prompt, the gap between the two can be large.