Every LLM request runs in two phases with different bottlenecks. Prefill reads the prompt and decode writes the answer, and RLMs spend most of their time in the first one.
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.
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.
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.
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.
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.
max_num_batched_tokens budget with prefill chunks. Smaller budgets such as 2048 give better ITL. Larger budgets give better TTFT.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.
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.
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.
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.
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.
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.
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.
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.