Inference Cache Can Be Slower Than Compute: The Hidden Cost of LLM Acceleration
This article explains why adding a shared cache in front of attention layers can leave median latency unchanged while pushing tail latency from about 3.96 seconds to 17.3 seconds. It breaks down the memory and bandwidth profile of low-rank compressed multi-head latent attention (MLA), the four hidden costs of reading cached blocks, a minimal inequality for estimating whether caching pays off, and five practical strategies such as tiered caching, adaptive granularity, early hit detection, bandwidth quotas, and observability loops.
1. A Counterintuitive Incident
A team built an inference service for a very large Mixture-of-Experts (MoE) model on a single node with eight high-end accelerator cards. To improve long-context throughput, they added a shared cache in front of the attention layers. The cache stored attention intermediates already computed for earlier requests, so that similar requests could reuse them directly.
The results after launch were awkward. Median latency barely moved, but tail latency for the slowest 1% of requests rose from about 3.96 seconds to 17.3 seconds. The team’s first instinct was a full rollback. During the postmortem, they realized the problem was not that “the cache was useless.” The problem was that reading from the cache itself costs money, and that cost had been badly underestimated during capacity planning.
2. How the Model Consumes GPU Memory and Bandwidth
To understand the failure, start with the workload characteristics. This class of model uses a low-rank compressed multi-head latent attention (MLA) design: each token’s keys and values are compressed into a shared low-rank vector. Regardless of the number of attention heads, the intermediate data per token is fixed and small. At FP8 precision, for example, every 256 tokens are packed into one block of roughly 12.4 MB, or about 48.4 KB per token.
These numbers have two direct consequences:
- Cache entries “look cheap,” so capacity is set very high and hit-rate metrics look good.
- What is actually expensive is not storage, but the GPU memory bandwidth and host-side copies required to move blocks in and out, plus the address computation and comparison needed to locate each entry.
3. Four Hidden Costs of Reading the Cache
- Addressing and comparison: A key must be derived from the prefix content, followed by hashing and block-by-block comparison. The longer the prefix, the more time key construction and collision handling take.
- Transfer bandwidth: Each hit moves more than ten megabytes of data into the working area. High hit rates combined with high concurrency saturate bandwidth quickly.
- Scheduling and synchronization: Cache reads and writes share the same queue as operator execution. Waiting on locks or waiting for copies to complete pushes requests into the tail.
- Capacity contention: GPU memory consumed by the cache could otherwise support larger batches and longer contexts. This degrades batch scheduling and indirectly raises latency.
When the compute savings from a hit are smaller than the sum of these four costs, the cache degrades from an “accelerator” into a “speed bump.” This explains why the median felt nothing while the tail exploded: tail requests are typically the ones with long prefixes that collide under high concurrency.
4. A Minimal Model for Quantifying the Cost
A simple inequality is recommended for pre-launch evaluation:
Benefit ≈ hit blocks × recompute time per blockCost ≈ hit blocks × fetch time per block + addressing overhead + synchronization wait + capacity opportunity lossEnable the cache only when Benefit > Cost
In practice, shadow traffic can be used to measure per-block fetch time and addressing overhead first, then feed those values back into the formula. This avoids “enabling the cache on intuition.”
5. Five Actionable Strategies
- Tiered caching: Keep hot blocks in fast on-chip storage, warm blocks in GPU memory, and cold blocks in host memory or object storage, with a different cost model per tier.
- Adaptive granularity: Do not cache short prefixes; cache only long ones. Adjust the threshold dynamically based on block size and hit probability.
- Early hit detection: Complete key construction and a fast hit check before queuing. On a miss, go straight to the compute path so the execution queue is not occupied.
- Bandwidth quotas and priorities: Give cache transfers a separate quota, prioritize tail-sensitive requests, and let batch background jobs yield.
- Observability loop: Use logging services and monitoring alerts to collect hit rate, transfer time, queue wait, and tail latency percentiles, forming a capacity regression loop.
An illustrative policy switch:
def should_use_cache(prefix_tokens, block_bytes, est_recompute_ms, est_fetch_ms):if prefix_tokens < MIN_PREFIX: # Skip caching for short prefixesreturn Falsereturn prefix_tokens * est_recompute_ms > prefix_tokens * est_fetch_ms + ADDR_COST
6. Turning Experience into a Standard
In general practice on platforms such as Baidu AI Cloud, inference acceleration usually follows the order “quantify first, then tier, then set quotas”: object storage carries cold data, a container platform orchestrates elastic replicas, and logging and monitoring systems drive capacity regression. The core point is not any single proprietary capability, but treating cache reads as a resource that has a cost and must be governed.
The conclusion is simple: there is no free lunch with caching. Only when transfer, addressing, synchronization, and capacity opportunity loss are accounted for can acceleration actually show up in tail latency, instead of turning common sense into an incident.
