When Caching Is Slower Than Computing: The Hidden Cost of Inference Acceleration
A shared cache added to speed up long-context inference can backfire, leaving median latency flat while pushing p99 latency from 3.96 seconds to 17.3 seconds. This article breaks down why reading a cache is not a zero-cost operation for large language model serving, using a single-node MoE deployment with MLA-style attention as the example. It explains how attention intermediate results reach roughly 48.4KB per token, why lookup, validation, data movement, tail-latency amplification, and eviction churn add up, and how benefit gating, chunked sparse hits, asynchronous prefetch, quota isolation, and observability can keep the cache only when it pays off.
1. The Assumption That Broke: The Acceleration Layer Slowed the System Down
An inference team at a cloud provider was serving an extremely large mixture-of-experts (MoE) model online on a single node equipped with 8 next-generation accelerator cards. To reduce response time for long-text scenarios, they placed a shared cache in front of the runtime. The cache stored attention intermediate results that had already been computed, on the expectation that similar requests would hit it and skip redundant computation.
The post-launch numbers were awkward: median latency barely moved, while the slowest 1% of requests (p99) rose from 3.96 seconds to 17.3 seconds. The team rolled the whole thing back at one point. The retrospective produced a single conclusion: reading a cache is not a zero-cost operation, and that cost has long been severely underestimated.
2. Understand the Workload First: How Large Are Attention Intermediate Results
Understanding the problem starts with understanding the shape of the data. The system uses a low-rank compression attention mechanism (commonly referred to in the industry as an MLA-style approach), which compresses each token’s key-value information into a shared low-rank vector, decoupling the intermediate data stored per token from the number of attention heads. At FP8 precision, every 256 tokens are packed into one block, and a single block is about 12.4MB, or roughly 48.4KB per token.
That “seemingly small” number is where the trap lies. A 100K-token context corresponds to roughly 1 million block positions, on the order of multiple TB of data movement and comparison. Deciding whether a request hits requires reading metadata, computing fingerprints, and running validation; a miss also means discarding data that has already been moved in. Computation is saved, but memory bandwidth and scheduling overhead are amplified.
3. Cost Breakdown: Four Reasons Cache Reads Are Slow
- Lookup and validation cost: fingerprint computation, hash table probing, and version and precision checks all execute serially on the critical path.
- Data movement cost: a hit means moving MB-scale blocks from remote storage into GPU memory, and once bandwidth is saturated, all requests queue together.
- Tail latency amplification: the cache is a shared resource, so one large block transfer blocks small requests, and p99 is blown up by a few heavy requests.
- Capacity and eviction churn: insufficient capacity causes frequent swap-in and swap-out, so the hit rate drops while the overhead is still paid in full.
4. The Fix: Make the Cache Work Only When It Pays Off
- Benefit-estimation gating: use the cache only when the estimated compute time saved is significantly higher than the movement and validation cost; otherwise compute directly.
- Chunking and sparse hits: shrink block granularity and reuse only the prefix segments that genuinely overlap, avoiding whole-segment transfers.
- Asynchronous and bypass paths: prefetch hit data asynchronously and decouple the miss path from cache lookup, eliminating critical-path blocking.
- Quotas and isolation: set bandwidth and capacity quotas by request length and tenant to prevent heavy requests from crowding out others.
- Observability: bring hit rate, bytes moved, lookup latency, and the p99 breakdown into monitoring, alerting, and logging services to close the loop.
if estimated_compute_saved > movement_and_validation_cost * safety_factor:use cache (async prefetch + chunked hits)else:compute directly, with cache lookup bypassed
5. Conclusion
The default assumption behind caching, that reading is cheaper than computing, does not hold in long-context large model scenarios. Only by governing the cache as a resource that has cost, capacity, and interference can p99 be pulled back from the teens of seconds into an acceptable range. If you are working on similar inference optimization, you can validate the gating and isolation strategies above in Baidu AI Cloud related practice first, then gradually ramp up traffic.
