Cache Hits Became the Bottleneck: The Unexpected Trap in Inference Latency Optimization
This article examines a counterintuitive failure mode in large-scale LLM inference: adding a shared attention cache to an 8-GPU MoE serving node left median latency unchanged but degraded p99 latency from 3.96 seconds to 17.3 seconds, forcing a rollback. It explains why caching can be slower than recomputation in inference workloads, analyzes the underlying causes such as memory bandwidth limits, lock contention, and request pattern mismatch, and proposes practical design principles including tiered caching, locality-aware scheduling, conditional caching, and runtime monitoring.
When building large-scale language model inference services, engineers often assume that caching automatically accelerates everything. However, one team encountered a counterintuitive phenomenon while serving an extremely large Mixture-of-Experts (MoE) model: after introducing a shared attention cache on a node with 8 high-end GPUs, the median latency stayed roughly unchanged, but the slowest 1% of requests (p99 latency) jumped from 3.96 seconds to 17.3 seconds. The team eventually had to roll back the feature. This case is not isolated. It highlights a deeper problem: when the complexity of a cache design outweighs the computation it saves, the cache itself can become a new performance killer.
Why Caching Can Fail in Inference Scenarios
Mismatch Between Cache Hit Rate and Request Patterns
The original purpose of a shared cache is to reuse previously computed attention matrices (Key-Value cache) and avoid redundant computation. But in real long-context inference workloads, the similarity between requests is often far lower than expected. Especially when user inputs contain highly personalized prefixes, random sampling parameters, or dynamically injected context, the cache hit rate may drop to single digits. A low hit rate means that most requests still require the full computation path, while the extra overhead introduced by the cache—such as lookup, memory access, and consistency maintenance—is spread across every single request.
Cache Access Path Can Be Longer Than the Compute Path
Attention computation is essentially dense matrix multiplication, which is highly parallelized on GPUs. Cache access, on the other hand, relies on memory addressing and data movement. When the cache is stored in host memory or in shared memory across nodes, a single cache access must traverse the PCIe bus or the network protocol stack, with latency far higher than the on-chip cache inside a GPU. More critically, there is a “scissors gap” between GPU compute power and memory bandwidth: modern GPU throughput grows much faster than memory bandwidth. Therefore, when a cache hit occurs, pulling data from remote memory to the compute core may take longer than simply recomputing the result.
Lock Contention and Consistency Overhead
A shared cache inevitably involves concurrent access from multiple threads or processes. Every read and write requires locking, updating metadata, and maintaining an LRU or LFU eviction list. On an 8-GPU node, multiple inference processes request cache entries simultaneously, and lock contention can cause severe serialization. In the case above, a likely contributor to the p99 spike was global mutex on cache metadata. Under high concurrency, the cache framework itself becomes a hot spot, and requests are blocked while waiting for locks, ultimately destroying tail latency.
Underlying Mechanisms: Why Cache Can Be Slower Than Computation
Memory Bandwidth Becomes the New Bottleneck
The complexity of attention computation is O(n²), where n is the sequence length. For long sequences, the computation is substantial, but GPU Tensor Cores handle it efficiently. The memory footprint of cached Key-Value data grows linearly with n, but the number of accesses can approach n² complexity. If a cache hit occurs, the KV data must be moved from memory, and the bandwidth consumed may exceed that required for direct recomputation. For MoE models in particular, expert parameters are distributed across multiple devices. When cached data must be transferred across cards, communication overhead is further amplified.
CPU Overhead of Cache Management
A cache hit requires a key-value lookup. If a hash table is used, hash computation and collision resolution consume CPU cycles; if a tree structure is used, multiple pointer dereferences are needed. Each individual operation is short, but at millions of requests per year, the cumulative overhead cannot be ignored. Even worse, synchronization between CPU and GPU may cause frequent blocking: the GPU waits for the CPU to finish the cache lookup, while the CPU waits for the cache lock to be released—a circular wait.
Why Tail Latency Gets “Amplified”
In distributed systems, p99 latency is often determined by queueing effects or resource contention. With a shared cache, an occasional cache miss that triggers fallback to recomputation adds “lookup time + recomputation time.” If the cache query path is itself unstable (e.g., due to GC pauses or network jitter), tail requests experience double delay. If the cache hits but memory bandwidth is saturated, latency also spikes. This unpredictability explains why p99 can degrade many times more than p50.
Classic Mistake: Caching for the Sake of Caching
Many engineers borrow cache strategies from database or web services and apply them directly to inference services. But inference services have three distinct characteristics:
- Compute-intensive and predictable: The input to attention is dynamic, but the computation structure is fixed. Recomputing on GPU can be very fast, especially when batch size is large—parallelism offsets the per-request cost.
- Strong state dependency: KV Cache is tightly bound to the context of a specific request. Its reuse scope is narrow; it cannot be shared across users like “hot pages.”
- Heterogeneous hardware resources: GPU memory, host memory, and remote storage have vastly different performance. Poor cache tier design can create a data funnel effect.
Engineering Practices: Designing a Cache That Actually Works
Tiered Caching with Dynamic Separation
Split the cache into several layers:
- GPU memory layer: Cache only the very small set of KV blocks most recently and frequently used (e.g., hot prefixes), with a hit rate above 95% in a very short window.
- Host memory layer: Cache full KV entries for medium-frequency access, but use lock-free hash tables or atomic operations, and batch reads to reduce PCIe transfers.
- Compute fallback strategy: When the cache hit rate falls below a threshold, disable the cache entirely to avoid extra overhead.
Adopt “opportunistic caching” rather than “full caching”—only enable caching when sequence length exceeds a certain threshold and system load is low.
Locality-Aware Scheduling
Cluster request prefixes to schedule similar requests to the same GPU node, giving cached data better spatial locality. For example, if many requests start with the same system prompt, keep that prompt’s KV cache resident in GPU memory and use a small dedicated index for lookup. Group users so that users in the same group share a cache pool, reducing cross-node access.
Asynchronous Prefetching and Predictive Updates
Do not make requests wait for cache filling. Introduce asynchronous prefetch threads that predict future KV data based on historical access patterns and load it into high-bandwidth layers during compute gaps. Use a write-back strategy instead of write-through to reduce latency after each inference step.
Monitoring and Dynamic Tuning
Monitor the following metrics in real time:
- Cache hit rate (split by request type)
- Average and p99 latency of cache access
- Cache memory bandwidth consumption as a percentage of total bandwidth
- Lock wait time and contention rate
When the ratio of “cache access latency” to “recompute latency” exceeds 1.2, automatically lower the cache priority. Use A/B testing to verify the benefit of different cache strategies under real traffic, rather than trusting theoretical speedups.
Beyond Rollback: A Better Solution with Conditional Caching
In the cited case, rolling back was a correct and conservative choice. A more refined approach is “conditional caching”—enable caching only for long-sequence requests, where recomputation is expensive and cache benefits are clear. For short sequences, compute directly. Additionally, change the cache granularity from “full document” to “segment,” reusing only high-similarity prefix blocks. This avoids extra overhead in most scenarios while retaining meaningful acceleration potential.
Conclusion
Caching is not a natural accelerator. In ultra-large-scale inference scenarios such as MoE models, the memory access, lock contention, and consistency management overhead of a cache can exceed the computation time it saves. The key principle for designing inference caches is: compare real latency rather than theoretical hit rates. Treat the cache as a multi-tier storage system that must match the hardware topology and request distribution. Introduce runtime monitoring and adaptive switches so the system can autonomously choose between “cache or compute” under different loads. As the case shows, the most effective optimization is sometimes “don’t optimize”—when evidence is insufficient, keeping a simple direct computation path is more reliable than adding a complex but inefficient cache layer. For developers, always rely on measured data and avoid being guided by common-sense inertia.
