LLM Inference Prefill vs. Decode: Understanding the Asymmetry

    This article explains why Prefill and Decode are fundamentally different workloads in large language model inference. It breaks down their computational goals, internal asymmetries, hardware bottlenecks, and the impact on capacity planning, cost control, and performance evaluation, along with general optimization practices. The analysis is vendor-neutral and applies to any LLM serving stack.

    When discussing LLM inference performance, many people treat Prefill and Decode as the same type of workload that simply differs in length. In reality, the two differ structurally in their computational goals, hardware bottlenecks, and resource planning. Understanding this asymmetry is a prerequisite for capacity planning, cost control, and performance evaluation in inference serving. This article takes a general technical perspective and does not cover any specific product.

    The Fundamental Difference Between the Two Phases

    Autoregressive generation splits a single request into two phases:

    1. Prefill: Reads the entire input tokens at once, builds the key-value cache (KV Cache), and produces the first output token.
    2. Decode: Based on the existing cache, processes only one new token per step and loops until generation finishes.

    The key difference is that Prefill is parallel computation involving large matrix-vector or matrix-matrix multiplications, while Decode is serial small-operator computation involving matrix-vector multiplication. The former is compute-intensive; the latter is memory-access-intensive.

    An Overlooked Detail: Prefill Is Not Fully Symmetric Either

    The industry often frames the asymmetry as Prefill versus Decode, but a closer look shows that asymmetry also exists within Prefill:

    • Except for the last position, all other positions only serve cache construction and do not need to pass through the subsequent output projection layer.
    • Only the last position produces the first token and must go through the full output path.

    For this reason, engineering implementations often separate “cache construction” from “first-token prediction” to avoid running the output projection on every position, reducing wasted computation. This shows that asymmetry is not a binary split but a common phenomenon throughout the computation graph.

    Hardware Bottlenecks: The Compute Wall and the Bandwidth Wall

    • Prefill: High arithmetic intensity that easily saturates compute, so the bottleneck is usually compute throughput.
    • Decode: Every generated token requires re-reading the entire cache and weights, resulting in low arithmetic intensity, so the bottleneck is usually memory bandwidth and cache capacity.

    The following illustrative pseudocode expresses this difference:

    1. # Prefill: process the entire input in parallel at once
    2. for layer in layers:
    3. K, V = project(all input tokens)
    4. cache.append(K, V)
    5. first_token = lm_head(last position of the last layer)
    6. # Decode: serial per token, repeatedly reading the cache
    7. while not done:
    8. q = project(single new token)
    9. attn = attention(q, cache) # reads all historical K/V
    10. cache.append(new K, new V)
    11. next_token = lm_head(attn)

    As shown, each iteration of the Decode loop touches the entire cache, which is the source of the bandwidth pressure.

    Impact on Capacity Planning and Cost

    1. Different batching strategies: Prefill is suited to large concurrent merged computation, while Decode is better served by continuous batching to improve utilization.
    2. The cache is a core cost item: The cache grows linearly with context length, so long-context scenarios require careful evaluation of memory usage and eviction strategies.
    3. Metrics must be viewed separately: First-token latency is mainly determined by Prefill, while overall throughput is more affected by Decode. Evaluating them together can easily lead to misjudgment.

    General Optimization Practices

    • Apply differentiated parallelism and batching configurations for Prefill and Decode;
    • Introduce cache reuse to avoid repeated prefilling for identical prefixes;
    • Use paged cache management to reduce fragmentation;
    • Observe the latency and utilization of the two phases separately through monitoring, alerting, and logging services;
    • Scale elastically on container platforms, allocating resources according to phase-specific pressure.

    Conclusion

    The asymmetry between Prefill and Decode is a structural fact of inference systems, and even Prefill itself is not fully symmetric. Only by acknowledging and quantifying this asymmetry can performance evaluation, resource planning, and cost control be built on the right model.