LLM Inference Performance Optimization: From Bottleneck Identification to Systematic Practice

    Anyone working on LLM inference eventually gets buried in jargon: KV cache, memory-access optimization for attention, speculative decoding. Each term is dropped in as if everyone already understands it. This article takes a different route. It first explains where the time actually goes — why training is compute-bound while inference splits into a compute-bound prefill phase and a memory-bandwidth-bound decode phase — and then organizes the common optimization techniques into two goals: moving less data, or moving it faster while overlapping movement with computation. It closes with a practical ordering of techniques by risk/reward and a note on protecting output quality along the way.

    People who work on inference optimization often get stuck on terminology from the very first conversation. Mention KV cache, memory-access optimization for attention, or speculative decoding, and every term is used as if the listener already knows it. A few sentences in, the listener is more confused than before.

    This article does not aim to pile up terminology. The goal is to explain clearly where the slowdown actually comes from, and only then discuss how to fix it. Optimizing without understanding the bottleneck is, in the end, optimizing blindly.

    Why Inference Bottlenecks Look Nothing Like Training Bottlenecks

    Most people apply their training intuition to inference. That is the first mistake.

    The core bottleneck in training is compute. Forward and backward passes repeatedly compute gradients, and every step involves massive matrix multiplications. Compute capacity — especially low-precision compute — is almost always saturated. This is a classic compute-bound workload.

    Inference is more complicated. Its execution splits into two phases with very different characteristics, and their bottlenecks do not even live on the same axis.

    The Two Phases of Inference: Prefill and Decode

    Prefill. The entire user prompt is fed into the model at once, and the hidden states for all input tokens are computed in parallel. Because tokens in the same batch have no ordering dependency among themselves, they can be processed together in matrix operations. This phase is compute-intensive, and GPU utilization is typically high.

    Decode. The model starts emitting tokens one at a time. Every new token requires reading back the information from all previously generated tokens to complete the attention computation. The process is strictly serial: token n cannot be computed until token n-1 is done. The problem is not the amount of arithmetic. The problem is that every single step has to move large volumes of weights and KV cache from device memory to the compute units. This phase is therefore a classic memory-bandwidth-bound workload.

    One conclusion is easy to overlook: in real production traffic, workloads with long prompts and short outputs are prefill-dominated, while conversational workloads and code completion, which generate long outputs, are decode-dominated. Before optimizing anything, you must determine which phase your workload is stressing.

    The Counterintuitive Core Fact: Most of the Time Goes to Moving Data

    Here is a genuinely counterintuitive fact: for the decode phase of an LLM, most of the time is not spent computing. It is spent moving data.

    A rough order-of-magnitude estimate makes the point. Take a mainstream datacenter-class GPU: compute on the order of hundreds of TFLOPS in half precision, and memory bandwidth on the order of a few terabytes per second. The two differ by roughly two orders of magnitude.

    Now do the arithmetic. A 7B-parameter model in FP16 needs about 14GB of memory for its weights. For every token generated, all 14GB of weights must in principle be read from memory into the compute units. At a few TB/s, simply reading the weights once costs several milliseconds. Which means: even with unlimited GPU compute, the act of moving weights alone caps per-GPU token generation at a little over one hundred tokens per second — and that is an optimistic figure. In real deployments you also read KV cache, and you pay scheduling and synchronization overhead, so the actual rate is lower still.

    Two concepts make this precise: the Roofline model and arithmetic intensity.

    1. arithmetic intensity = compute (ops) / memory traffic (bytes)
    2. ↑ high: compute-bound → the optimization target is "compute more"
    3. ↓ low: memory-bound → the optimization target is "move less"
    4. Each decode step processes only 1 new token but must move all the weights,
    5. so arithmetic intensity is extremely low, and performance stays pinned
    6. well below the memory-bandwidth roof.

    This leads to the central tension of inference optimization: your GPU spends most of its time waiting for data rather than computing on data.

    Two Families of Optimization

    Once that tension is clear, the sprawling set of techniques falls into two groups:

    • Reduce the volume of data that has to move: quantization, pruning/sparsification, KV cache compression.
    • Improve movement efficiency and overlap computation with data movement: parallelism strategies, operator fusion, scheduling optimization, speculative decoding, continuous batching.

    4.1 Reducing the Volume of Data Moved

    Quantization. Compressing weights from FP16 down to INT8, INT4, or lower cuts the number of bytes that must be moved proportionally. Halve the bit width and the theoretical decode ceiling roughly doubles, which makes this one of the highest-value techniques available today. The trade-off is accuracy loss, and the options differ: post-training weight quantization, activation quantization, and per-channel or per-group quantization each produce different accuracy outcomes. Conceptually:

    1. # Conceptual illustration: quantize weights from FP16 to INT4, reducing traffic to 1/4
    2. w_fp16 = load_weights(dtype="float16") # 2 bytes per parameter
    3. scale, zero = calibrate(w_fp16)
    4. w_int4 = quantize(w_fp16, bits=4) # 0.5 bytes per parameter
    5. # Dequantize with scale/zero at compute time, or run a low-precision kernel directly

    Pruning and sparsification. Removing redundant weights or introducing structured sparsity reduces the effective parameter count. The difficulty is that modern GPUs accelerate irregular sparsity only modestly, so structured sparsity — pruning whole blocks or whole columns — tends to be more practical than unstructured approaches.

    KV cache compression. During decode, the KV cache grows linearly with sequence length. It consumes both memory capacity and bandwidth. Common approaches include: keeping cache for only a subset of historical tokens, quantizing the cache, multi-query or grouped-query attention (letting multiple query heads share K/V to shrink the cache), and paged memory management that allocates cache blocks on demand to reduce fragmentation and waste. This class of optimization pays off most in long-context, high-concurrency scenarios.

    4.2 Improving Movement Efficiency and Overlapping Compute with Memory Access

    Operator fusion. Merging many small operators into a single kernel avoids writing intermediate results back to device memory only to read them again. Memory-access optimization in attention computation — performing tiled computation with data kept in on-chip cache and avoiding spills to device memory whenever possible — is a typical example of this approach, and it substantially reduces attention’s memory traffic.

    Parallelism strategies. When a single GPU cannot hold the model or cannot run it fast enough, tensor parallelism (splitting the matrices within a layer across multiple GPUs) and pipeline parallelism (placing different layers on different GPUs) spread memory pressure and raise throughput. The core trade-off here: the higher the degree of parallelism, the greater the inter-GPU communication cost — especially all-reduce — so scheduling that overlaps communication with computation becomes critical.

    Speculative decoding. A lightweight draft model guesses several candidate tokens at once, and the large model then verifies those candidates in parallel. Correct guesses pass through in a single step; incorrect ones are rolled back. Because verifying multiple tokens can be done in parallel, this technique parallelizes part of the serial decode loop without changing the final output distribution, raising effective throughput.

    Continuous batching. Traditional static batching waits for an entire batch to finish before admitting the next one, so outputs of differing lengths leave the GPU idle for long stretches. Continuous batching schedules dynamically at the token level: the moment one request finishes, a new one is inserted. This significantly improves GPU occupancy and overall throughput, and combined with the paged cache management mentioned above, it further reduces fragmentation.

    4.3 A Practical Order of Operations

    Optimization should not be attempted all at once. Proceed in order of value-to-risk ratio:

    1. Use profiling tools first to confirm whether the bottleneck is in prefill or decode, and whether it is compute-bound or bandwidth-bound.
    2. Apply quantization first, especially weight quantization — it delivers results quickly and requires little change.
    3. For high-concurrency workloads, add continuous batching plus paged KV cache management.
    4. For long-context workloads, focus on KV cache compression.
    5. When chasing maximum throughput, introduce speculative decoding, multi-GPU parallelism, and operator fusion.
    6. At every step, run a fixed evaluation set to regression-test accuracy and hold the quality line.

    Conclusion

    The essence of inference optimization fits in one sentence: decode is usually bound by memory bandwidth, not by compute. Every technique — quantization, KV cache compression, parallelism, fusion, speculative decoding, continuous batching — belongs to one of two lines: move less data, or move it faster while overlapping movement with computation. Draw the bottleneck map first, then choose techniques. That is how you avoid spinning in place inside the terminology. And when you take this approach into production, general-purpose containerized deployment, elastic scaling, monitoring and alerting, and log analysis capabilities on a cloud platform turn performance tuning from a one-off experiment into an engineering practice of continuous observation and iteration.