When Caching Is Slower Than Computing: The Hidden Cost of Inference Acceleration
This article examines a counterintuitive failure in LLM inference: enabling a shared prefix cache made p99 tail latency worse even though p50 stayed flat. Using a large MoE model with low-rank compressed attention (MLA-style) and FP8 block packing as the example, it explains why cache reads can cost more than the computation they replace—covering bandwidth and read amplification, capacity pressure and eviction thrashing, head-of-line blocking in shared execution queues, and key/version consistency overhead. It then presents a practical fix set: sub-block and paged layouts with tiered storage, cost-benefit admission control before reads, asynchronous loading with priority isolation, value-based eviction with a pinned region, and observability metrics such as read amplification ratio and batch gap. A rollout checklist and common pitfalls are included.
1. A Counterintuitive Result: Tail Latency Collapsed Once Caching Was On
A team was serving online inference for a very large Mixture of Experts (MoE) model. The model scales total parameter count without linearly increasing the compute per token, by routing different parameter subsets to different tokens. The hardware was a single node with 8 high-performance accelerator cards, and the service target was long-context requests.
To speed up long inputs, the team added a shared cache layer: previously computed attention intermediates were retained and reused when incoming requests shared the same or a highly similar prefix, which should have skipped redundant computation. The measured results after rollout were the opposite of expectations:
- Median latency (p50) barely moved;
- Tail latency (p99) degraded from roughly 3.96 seconds to roughly 17.3 seconds;
- The team ended up rolling the feature back entirely.
This was not “the cache does nothing.” It was that the cost of reading the cache had been severely underestimated. Understanding why requires looking at how the model and the hardware interact.
2. Background: The Attention Compression Layout Determines the Cache’s “Physical Shape”
Models of this class generally use a low-rank compressed attention variant (commonly referred to in the industry as an MLA-style approach): each token’s key and value information is compressed into a shared low-rank vector, so the intermediate state that must be stored per token is fixed and small regardless of how many attention heads there are.
In the scenario described here, FP8 precision is used, and every 256 tokens are packed into one “block,” with a single block being about 12.4 MB—roughly 48.4 KB per token. Both numbers matter a lot:
- A small per-token size means “hitting one token” saves almost no time;
- A large per-block size means “loading a whole block to hit a few tokens” amplifies I/O.
An illustrative capacity estimate:
Block size = 12.4 MBTokens per block = 256Cost per token = 12.4 MB / 256 ≈ 48.4 KBIf a request prefix hits 1000 tokens:Theoretical compute saved ≈ prefix attention compute for 1000 tokensActual data moved ≈ ceil(1000 / 256) * 12.4 MB ≈ 49.6 MB
The conclusion is straightforward: cache benefit is denominated in “amount of computation,” while cache cost is denominated in “memory bandwidth and capacity.” The units differ, so the two cannot be subtracted directly.
3. Why Cache Reads Can Be Slower Than Compute: Four Cost Chains
3.1 Bandwidth Cost: Moving Data Costs More Than Computing
Under the compressed layout, attention computation has already been significantly slimmed down, while reading the cache requires moving compressed blocks from memory to the compute units. When the block granularity is far larger than the actual hit length, effective bandwidth utilization is very low, and read amplification becomes the dominant term.
3.2 Capacity Cost: Eviction Thrashing
A shared cache must hold blocks for many requests and many prefixes, and the capacity pressure causes frequent evictions. An entry that was just established gets pushed out, creating thrashing; the hit rate becomes unstable and the benefit cannot be amortized.
3.3 Scheduling Cost: Head-of-Line Blocking
Cache loading typically shares the same execution resources as the compute stream. A large block load blocks the batching cadence of other requests. p50 is determined by the majority of short requests, so it shows no change; p99 is determined by “the batch that got blocked,” so it degrades sharply.
3.4 Consistency and Lifecycle Cost
Prefix sharing requires key design, versioning, and invalidation management. Keys that are too fine lower the hit rate; keys that are too coarse cause incorrect reuse. Poor lifecycle management turns an apparent hit into extra validation overhead.
4. The Fix: Turn the Cache From “On by Default” Into “Enabled Conditionally”
4.1 Move From Block Granularity to On-Demand Sub-Blocks and a Tiered Cache
- Introduce finer sub-blocks or a paged layout to reduce read amplification;
- Use a tiered structure: hot data in the fast memory region, warm data in host memory, cold data in object storage or a distributed cache;
- Goal: make “hitting 1000 tokens” move an amount of data close to 1000 tokens.
Illustrative pseudocode:
def fetch_prefix(prefix_tokens, cache):# Fetch only the minimal set of pages covering the hit range, avoiding whole-block loadspages = cache.page_index.lookup(prefix_tokens)missing = [p for p in pages if not cache.is_local(p)]if missing:cache.prefetch_async(missing) # Backfill asynchronously, without blocking the main computereturn cache.gather_local(pages) # The hit portion is immediately usable
4.2 Admission Control: Decide Whether Reading Is Worth It First
Before reading, run a cost-benefit check and take the cache path only when the benefit is significant:
est_saved_compute = hit token count * per-token compute costest_io_cost = pages to load * page size / effective bandwidthEnable condition: est_saved_compute > α * est_io_cost (α is a safety factor, empirically > 1)
This admission threshold is the key to pulling p99 back into a normal range: it stops low-hit, high-transfer requests from polluting the overall queue.
4.3 Asynchrony and Priority Isolation
- Route cache loading through a separate queue with its own resource quota, so it does not compete with the critical compute stream;
- Assign low priority and a timeout to load tasks; on timeout, abandon the load and compute directly;
- Separate paths for latency-sensitive requests (interactive) and throughput-oriented requests (batching).
4.4 Capacity and Eviction Policy
- Evict by “block value” rather than “most recently used”: value = reuse probability × hit savings × remaining lifetime;
- Reserve a pinned region for the prefixes of currently active requests to avoid thrashing;
- Monitor three core metrics: hit rate, read amplification ratio, and eviction rate.
4.5 Observability: Make the “Hidden Cost” Visible
The following metrics must be collected and put on dashboards; otherwise the problem can only be discovered through rollback:
- Cache hit rate (measured both per token and per page);
- Read amplification ratio = actual bytes moved / theoretical bytes for hit tokens;
- Load wait time distribution (p50/p95/p99);
- Batching gaps caused by caching (batch gap);
- Eviction rate and pinned region occupancy.
5. Rollout Checklist and Common Pitfalls
Suggested rollout order:
- Add metrics first, reproduce the p99 degradation, and locate the read amplification;
- Then add admission control to stop the bleeding quickly;
- Then switch to a paged layout and asynchronous loading;
- Finally tune capacity and eviction policy for long-term optimization.
Common pitfalls:
- Looking only at hit rate, not read amplification;
- Evaluating cache effectiveness with p50;
- Sharing one execution queue between caching and compute;
- The intuition that “bigger blocks always save more.”
6. Conclusion
“Cache is always faster than compute” is a widely assumed piece of common sense, but in an inference system with low-rank compressed attention, large block packing, and shared execution resources, reading the cache is a real resource transfer whose cost shows up concentrated in tail latency. The engineering-correct move is not to turn the cache off, but to give it a cost model, an admission threshold, asynchronous isolation, and observability. In general inference practice on platforms such as Baidu AI Cloud, this “quantify the cost before enabling the optimization” approach applies equally to general capabilities like object storage, message queues, container platforms, and monitoring and alerting: any optimization should first answer “what is the cost, and under what conditions is it worthwhile.”
