LLM Inference Performance Optimization: Find the Bottleneck First, Then Fix It

    This article explains why large language model inference is slow and how to speed it up. It breaks inference into the Prefill and Decode stages, shows why the real constraint is usually memory bandwidth rather than raw compute, and organizes the main optimization techniques into two categories: reducing the amount of data that has to be moved and improving how efficiently it moves. Developers with a basic understanding of the Transformer architecture can use this as a practical framework for diagnosing bottlenecks and choosing the right optimization for their scenario.

    In many technical talks, “LLM inference optimization” is one of the easiest topics to get wrong. Start listing terms like KV cache, quantization, and speculative decoding, and the audience tends to get more confused the longer you go. The root cause is simple: people who do the optimization are used to thinking in jargon, but forget that their audience needs a map of the “why.” This article takes a different angle. It first explains why inference is slow, then discusses how to optimize it. The goal is to give developers who understand the basics of the Transformer a systematic mental framework for inference acceleration.

    Step 1: Locate the bottleneck — where is inference actually slow?

    The cardinal sin of optimization is prescribing a cure before diagnosing the disease. Inference and training have different bottlenecks. Training is mainly limited by compute: large matrix multiplications and gradient updates consume most of the FLOPs. Inference — especially autoregressive generation — usually hides its bottleneck somewhere else: data movement. Understanding this is the prerequisite for everything that follows.

    Prefill and Decode: two phases with fundamentally different behavior

    LLM inference splits cleanly into two phases:

    • Prefill phase: The entire user prompt is fed into the model at once, and the hidden states for all tokens are computed in parallel. Because every position can be computed simultaneously, this phase is compute-intensive and can fully saturate the GPU’s FLOPs.
    • Decode phase: Tokens are generated one at a time. Each new token must attend back to all previous tokens. Only one position is computed per step, yet a massive amount of existing data has to be read. This makes it memory-bandwidth-intensive.

    The same model shows completely different performance profiles in these two phases. That is also why optimization strategies usually need to be designed per phase, rather than relying on a single configuration to do everything.

    The core contradiction: compute is abundant, bandwidth is tight

    Here is a counterintuitive fact: most of the inference time is not spent “computing” — it is spent “waiting for data to move from memory to the compute units.”

    Take a mainstream data-center GPU as an example. Its half-precision (FP16/BF16) compute can reach hundreds of TFLOPS, while memory bandwidth is on the order of 2TB/s. The two differ by orders of magnitude. Suppose a 7B-parameter model uses roughly 14GB in half precision. In theory, generating every single token requires reading all 14GB of parameters from memory into the compute units:

    1. 14GB ÷ 2TB/s ≈ 7ms (parameter read time only)
    2. 1000ms ÷ 7ms ≈ up to ~140 tokens per second

    In other words, even if the GPU had infinite compute, the mere act of “moving the parameters out” caps generation at around a hundred-something tokens per second. Add the cost of reading the KV cache and other overhead, and real-world throughput is even lower. This is the so-called “memory bandwidth wall,” and it is the core contradiction of inference optimization: the GPU spends most of its time waiting, not computing.

    Splitting optimization into two categories

    Once you grasp this contradiction, almost every inference optimization technique falls into one of two categories:

    1. Reduce the amount of data that has to be moved: make each transfer move fewer bytes.
    2. Improve transfer efficiency / overlap compute with movement: use bandwidth more fully, or keep the GPU from sitting idle.

    The rest of this article expands on each.

    Reducing the amount of data to move

    Quantization: Compress weights and activations from FP16 down to INT8, INT4, or even lower bit widths. The parameter footprint is cut in half or to a quarter, the data moved per transfer drops, and bandwidth pressure eases. The trade-off is precision loss, so practice relies on strategies such as group-wise quantization and mixed precision to balance compression against accuracy.

    KV cache compression: During autoregressive generation, the Key/Value of historical tokens must be cached to avoid recomputation, but as the sequence grows the cache itself balloons into a new bandwidth and memory burden. Common approaches include keeping only part of the history, quantizing the cache, or merging and sharing the cache of adjacent tokens — all of which reduce this overhead.

    Sparsity and pruning: Removing unimportant weights or attention connections reduces the amount of parameters involved in computation and movement. The gains can be significant, but the approach is more sensitive to accuracy and requires careful evaluation and regression testing.

    Improving transfer efficiency: stop letting the GPU idle

    Continuous batching: Traditional batch processing requires all requests in a batch to either start together or finish together, so short requests wait on long ones and GPU utilization swings up and down. Continuous batching lets new requests join the queue at any moment and completed requests leave immediately, packing memory and compute more tightly and substantially raising overall throughput.

    Operator fusion and IO-aware attention: GPU memory access has its own launch and scheduling overhead, and merging several small operators into a larger one reduces this waste. Attention is especially memory-access-heavy, so the industry commonly uses tiling-based, IO-aware schemes that keep attention computation in on-chip high-speed cache as much as possible, reducing repeated reads and writes to memory — speeding things up without changing the result.

    Parallel strategies: When a single GPU cannot hold the model, or a single GPU does not have enough compute to bring latency down, tensor parallelism, pipeline parallelism, and similar approaches can split the model across multiple GPUs to compute collaboratively. Parallelism raises throughput and reduces latency, but introduces inter-GPU communication overhead, so the split must be chosen carefully according to the network topology.

    Speculative decoding: A smaller, faster model first “guesses” several candidate tokens, and the large model then verifies them all at once. Because verifying multiple positions costs fewer transfers than generating them one by one, when the hit rate is high enough this produces more tokens with fewer large-model forward passes. It is a decoding technique that speeds things up without changing the final output distribution.

    Choosing in practice: the right fix for the right problem

    These techniques are not “better the more aggressive.” They need to match the scenario:

    • Low latency, modest throughput pressure: prioritize compression and quantization plus IO-aware operator optimization to bring down single-request latency.
    • High throughput, heavy concurrency: prioritize continuous batching and parallel scaling to fully load the hardware.
    • Very long sequences: focus on KV cache compression, otherwise long context will consume the entire bandwidth advantage.
    • Accuracy-sensitive: keep quantization bit widths conservative and run thorough accuracy regression testing.

    When deploying, first do a clear performance profile to determine whether the bottleneck sits in Prefill or Decode, and whether it is bandwidth-bound or compute-bound, then apply targeted techniques rather than piling on every optimization at once. At the same time, the deployment layer can use general-purpose capabilities such as container scheduling, monitoring and alerting, and log analysis to continuously observe throughput and latency metrics, making the optimization measurable and repeatable.

    Summary

    The main thread of LLM inference optimization comes down to one sentence: inference is slow because it moves data, not because it computes. Once you understand the difference between Prefill and Decode and the nature of the memory bandwidth wall, every optimization technique fits neatly into two categories: reducing the amount of data moved and improving how efficiently it is moved. Locate the bottleneck first, then apply the right fix, and pair it with continuous performance observation — that takes you from “showing off jargon” to “explaining the why clearly and executing it well.”