LLM Inference Performance Optimization in Practice: From Bottleneck Identification to System Acceleration

    A practical guide to optimizing LLM inference performance. It explains why most inference workloads are bound by memory bandwidth rather than compute, how to use roofline thinking and arithmetic intensity to locate the bottleneck, and the very different performance profiles of the Prefill and Decode phases. It then organizes optimization techniques into two main lines—reducing data movement (quantization, pruning, KV Cache compression) and improving movement efficiency and compute overlap (parallelism, operator fusion, continuous batching, speculative decoding)—so you can make evidence-based, measurable optimization decisions.

    1. Before Optimizing, Answer “Where Exactly Is It Slow?”

    Many inference optimization efforts deliver little because techniques are applied without first locating the bottleneck. Training and inference have fundamentally different bottleneck profiles. Training’s core pressure is computation—large numbers of matrix multiplications for backpropagation of gradients. Inference is more complicated: its performance constraint is often not that computation is slow, but that data movement is slow. Without understanding this, any optimization pushes in the wrong direction.

    To optimize, start with roofline thinking: any operator is either compute-bound or memory-bound. The test is simple—look at arithmetic intensity, the number of floating-point operations supported per byte of data moved. When arithmetic intensity falls below the hardware’s “compute/bandwidth” ratio, the system is bandwidth-bound, and adding compute is pointless.

    2. The Two Phases of Inference: Prefill and Decode

    LLM inference is usually split into two phases with very different performance profiles:

    • Prefill phase: The entire input prompt is fed into the model at once, and the hidden states for all input tokens are computed in parallel. Because tokens at the same moment can be processed in parallel, the matrices are large and arithmetic intensity is high. This phase is typically compute-intensive and can saturate the available compute well.

    • Decode phase: Tokens are generated one at a time, and each new token requires attention over the information from all previous tokens. Here the “number of rows” in each matrix operation is just 1, so the matrix degenerates into a vector-by-matrix multiplication with extremely low arithmetic intensity—a classic memory-bandwidth-intensive scenario.

    The key issue is this: in real serving, especially for long-text generation and conversational scenarios, the vast majority of wall-clock time is spent in the Decode phase. And the Decode phase is precisely where compute is underutilized and bandwidth is saturated.

    3. A Counterintuitive Truth: Compute Is Abundant, Bandwidth Is Tight

    Consider an order-of-magnitude estimate (using a mainstream datacenter-class accelerator as an example, with FP16 compute in the hundreds of TFLOPS range and memory bandwidth around 2TB/s).

    Assume a 7-billion-parameter (7B) model. At FP16 precision, the parameters occupy about 14GB. In the Decode phase, generating each token theoretically requires moving all 14GB of weights from memory through the compute units. At a bandwidth of 2TB/s (about 2000GB/s):

    1. single transfer time = 14GB ÷ 2000GB/s = 7ms
    2. theoretical max token/s = 1000ms ÷ 7ms ≈ 140 token/s

    The conclusion is striking: even if GPU compute were infinite, merely “reading out the parameters” caps single-card, single-stream generation at around 140 tokens per second. Faster computation doesn’t help because the data hasn’t been moved into place yet. And this is only an ideal figure—in reality, KV Cache reads and writes, kernel launch overhead, and scheduling gaps all further reduce actual throughput.

    4. The Core Contradiction: The GPU Spends Most of Its Time “Waiting for Data”

    This yields the essential contradiction of inference optimization: the accelerator spends most of its time waiting for data to flow in from memory rather than actually computing. This also explains why raising MFU (compute utilization) is so difficult in the Decode phase: arithmetic intensity is too low, leaving compute units idle or half-idle for long stretches.

    Once you understand this contradiction, every optimization technique falls into one of two main lines:

    1. Reduce the amount of data that needs to be moved;
    2. Improve movement efficiency, or overlap computation with movement.

    5. Main Line One: Reduce Data Movement

    Since the bottleneck is “moving too much,” the most direct idea is to move less.

    • Quantization: Compress weights and activations from FP16/FP32 to INT8, INT4, or even lower bit widths. Weights drop from 14GB to 7GB or even 3.5GB, cutting per-transfer volume by multiples and improving Decode speed almost linearly. Common approaches include post-training quantization (PTQ) and quantization-aware training (QAT). The core challenge is controlling precision loss at low bit widths, which is what group quantization, per-channel quantization, and similar techniques are designed to address.

    • Pruning: Remove redundant weights or non-critical structures. This splits into structured pruning (directly deleting channels/heads, which is hardware-friendly) and unstructured pruning (sparsification, which depends on specialized sparse operators to realize gains). Pruning reduces both storage and movement, but requires accompanying fine-tuning to recover precision.

    • KV Cache compression: In the Decode phase, beyond the weights, the Key/Value cache of historical tokens grows with the sequence length and becomes a dual burden on bandwidth and memory. Common techniques include MQA/GQA (having multiple query heads share Key/Value heads to substantially compress cache size), KV quantization, and attention-importance-based cache eviction strategies. This kind of optimization is especially critical for long-context scenarios.

    6. Main Line Two: Improve Movement Efficiency and Compute Overlap

    Beyond reducing data volume, make both “moving” and “computing” more efficient and able to overlap.

    • Parallelism strategies: Using tensor parallelism (splitting a single layer’s weights across multiple cards), pipeline parallelism (splitting by layers), and combinations with data parallelism to spread out workloads that a single card can’t hold or can’t fully utilize. Parallelism both breaks through the memory capacity wall and eases insufficient single-card bandwidth by aggregating bandwidth across multiple cards.

    • Operator Fusion: Fuse multiple small operators (such as matrix multiply + bias + activation, or the QKV projection and softmax inside attention) into a single kernel, reducing repeated reads and writes of intermediate results to memory and lowering the number of kernel launches. This pays off significantly in low-arithmetic-intensity scenarios, because what is saved is precisely the memory round-trip overhead.

    • Continuous Batching: Traditional static batching requires a batch of requests to generate in sync and finish together, so short requests must idle while waiting for long ones—a serious waste. Continuous batching schedules dynamically at the token level: a sequence exits the moment it finishes and a new request is added immediately, significantly improving overall throughput and bandwidth utilization. Its scheduling logic can be abstracted as:

    1. each step loop:
    2. 1. collect all currently active sequences
    3. 2. generate one token for each sequence (packed into one batch)
    4. 3. update each sequence's KV Cache
    5. 4. move completed (EOS/reached limit) sequences out, add newly arrived requests
    • Speculative Decoding: A small “draft model” first guesses several tokens in a row, then the large model verifies them all in parallel at once. If the guesses are correct, one step produces multiple tokens, turning what were serial Decode steps into a single parallel, Prefill-style verification—raising output per unit time under bandwidth constraints. In essence, it is “trading one large transfer for the output of multiple tokens.”

    7. Methodology Summary

    The right way to approach LLM inference optimization is to first quantify and locate the bottleneck, determine whether it is compute-bound or memory-bound, and then apply the appropriate remedy. In the Decode phase, prioritize a combination of “reduce movement + improve overlap efficiency”—quantization and KV Cache compression reduce data volume, continuous batching and speculative decoding boost throughput, and operator fusion and parallelism reduce overhead. Once you internalize this mental map, you can quickly judge which link in the contradiction any specific optimization technique acts on, and thereby make well-grounded, measurable optimization decisions.