LLM Inference Optimization: When KV Cache Reuse Is Slower Than Recomputation
Shared KV cache reuse can reduce repeated computation, but it can also increase latency in large-scale LLM inference. This article examines a MoE model using Multi-head Latent Attention, where enabling cache reuse pushed P99 latency from 3.96 to 17.3 seconds. It explains how fragmented memory access, concurrency overhead, and scheduling stalls undermine caching, and how memory layout, asynchronous prefetching, topology-aware scheduling, and finer-grained concurrency can address these bottlenecks.
Introduction: When Caching Breaks the Usual Performance Assumptions
In software engineering, caching is a standard response to performance bottlenecks. CPU caches, distributed caches such as Redis, and the KV cache used in large language model inference all follow the same principle: trade storage for time by avoiding repeated computation.
Yet large-scale LLM inference can challenge this assumption. In some circumstances, retrieving cached data takes longer than recomputing it.
This article examines an inference optimization case involving a Mixture-of-Experts (MoE) model with Multi-head Latent Attention (MLA). A shared cache intended to accelerate requests instead became a system bottleneck. Understanding why required looking beyond cache hit rates to memory access patterns, concurrency, and GPU scheduling.
The Case: A Cache Optimization That Increased Tail Latency
The inference service ran a very large MoE model on a compute node equipped with eight high-end GPUs. MoE architectures increase model capacity without a proportional increase in computation, using a routing mechanism to select experts for different inputs.
To improve response times for long inputs, the engineering team introduced shared KV cache reuse. The goal was to retain previously computed attention state and reuse it when subsequent requests shared a reusable prefix, avoiding substantial repeated computation.
The production results were disappointing. Median latency remained nearly unchanged, while P99 latency—the latency threshold below which 99% of requests fall—jumped from 3.96 seconds to 17.3 seconds.
The deterioration in tail latency significantly affected the user experience, forcing the team to roll back the feature.
Understanding MLA and Its Cache Storage Characteristics
To understand why cache reuse became a bottleneck, it helps to examine the model’s attention architecture.
Conventional attention stores key and value tensors for each token, so KV cache memory grows with context length. MLA reduces this storage requirement by compressing the key-value information into a shared low-rank latent representation.
This makes the cached representation compact rather than requiring separate full-size key-value data for every attention head.
In the system described here, the cache used FP8 precision and grouped every 256 tokens into a block. Each block occupied approximately 12.4 MB, or roughly 48.4 KB per token across the cached state.
At first glance, this looks well suited to reuse: smaller cached representations reduce memory pressure and the volume of data that must be retrieved.
However, compact storage does not automatically mean efficient access. The way those blocks are allocated, located, and read can matter as much as their size.
Why the Cost of Cache Retrieval Was Underestimated
The investigation identified three main sources of the P99 latency increase. Together, they showed that a cache hit is not free: retrieving and coordinating cached state can introduce substantial overhead.
1. Fragmented GPU Memory and Scattered Access
Although MLA reduced the amount of cached data, the cache was stored in blocks scattered across GPU memory.
Retrieving reusable state required many small, noncontiguous memory accesses. High-end GPUs provide enormous memory bandwidth, but fragmented reads can use that bandwidth poorly. Instead of benefiting from large, efficient transfers, requests incur access and memory-controller scheduling overhead.
The result was a mismatch between the hardware’s peak bandwidth and the effective bandwidth available to cache retrieval.
2. Contention and Synchronization Overhead
Multiple inference requests accessed the shared cache concurrently. Maintaining consistency required locking or other concurrency-control mechanisms.
Under load, a large request could hold access to an important cache block while other requests queued behind it. This blocking disproportionately affected the slowest requests.
As concurrency increased, contention could compound, pushing up P99 latency even when the median remained relatively stable.
3. Uncertain Cache Hits Disrupted the Compute Pipeline
In an ideal execution path, a cache hit skips redundant computation, while a miss simply proceeds with normal computation.
In practice, scheduling had to accommodate uncertain cache availability. GPU execution could stall while waiting for retrieval results or transitioning between cached and uncached paths.
These interruptions disrupted otherwise efficient operator fusion and computation pipelines. GPU compute units spent more time idle, and overall throughput could decline rather than improve.
The central issue was therefore not merely whether the cache contained reusable data. It was whether that data could be delivered without interrupting the rest of the inference workload.
Redesigning the Cache to Deliver a Net Performance Benefit
Rather than abandoning cache reuse, the team reworked the system around its actual bottlenecks.
1. Improve Memory Layout: Replace Scattered Reads with Contiguous Access
To address fragmentation, the team redesigned cache allocation around a preallocated, contiguous memory pool instead of scattered, on-demand allocations.
A custom memory manager reorganized frequently reused KV cache blocks in GPU memory. This allowed the GPU to retrieve data through larger, more efficient memory transactions, improving effective bandwidth utilization.
The lesson is that a compact cache representation still needs an access-friendly layout. Reducing stored bytes alone does not guarantee faster retrieval.
2. Overlap Retrieval with Computation Through Asynchronous Prefetching
The system introduced asynchronous prefetching to reduce blocking between cache access and computation.
When a request entered the scheduling queue, the system used historical information to anticipate which cache blocks were likely to be reused. It then initiated retrieval for the next stage while the GPU continued computing the current stage.
Overlapping computation and memory access helped hide retrieval latency rather than exposing the full cost on the request’s critical path.
3. Use Topology-Aware Scheduling in Cloud-Native Deployments
For large inference deployments, optimization within a single node is only part of the problem. Cache sharing across instances must also account for the underlying interconnect topology.
On container platforms or high-performance computing infrastructure with topology-aware scheduling, inference instances that share cached state can be placed within the same high-bandwidth interconnect domain, such as a domain connected through an NVLink Switch.
Where the infrastructure supports this placement, it reduces the need for expensive cache transfers across nodes.
Cloud-native monitoring and alerting also help identify changes in P99 latency. These signals can inform adjustments to cache eviction policies, preventing cold data from consuming capacity and transfer resources needed by frequently reused blocks.
The relevant principle is infrastructure-aware placement, rather than assuming that every shared-cache deployment has equivalent access costs.
4. Replace Coarse-Grained Locks with Finer-Grained Concurrency
To reduce contention, the cache design moved away from coarse-grained global locks toward lock-free data structures based on Compare-And-Swap (CAS), combined with separate read and write paths.
Readers accessed cached data through a read-only path without acquiring the original shared locks. Writers updated the cache asynchronously through an append-log mechanism.
This design targeted the blocking behavior that had amplified tail latency, allowing reads to proceed without waiting behind coarse-grained write operations.
Conclusion: Caching Is Not a Universal Performance Fix
“Add a cache” is not a reliable shortcut to faster inference.
Large MoE models and MLA can make efficient use of computation and storage, but their benefits depend on the surrounding system design. A smaller KV cache may still be expensive to retrieve if access is fragmented, synchronization creates queues, or scheduling interrupts GPU execution.
This case illustrates why cache reuse must be evaluated as an end-to-end optimization. Its cost includes memory bandwidth utilization, concurrency control, transfer topology, and interaction with the compute pipeline—not just the amount of computation avoided.
By aligning memory layout, prefetching, scheduling, and concurrency with the hardware and data structures, engineers can make cache reuse serve its intended purpose: reducing latency while supporting efficient, stable LLM inference.
