When Caching Is Slower Than Compute: The Hidden Cost of Inference Acceleration
This article examines why adding a shared cache to accelerate long-context inference in large-scale Mixture-of-Experts (MoE) serving can backfire, using a real stress-test case where median latency stayed flat while p99 latency jumped from about 3.96 seconds to 17.3 seconds. It explains how cache cost is driven by block size, access frequency, and data movement paths rather than saved floating-point work, breaks down the four mechanisms behind tail-latency explosions, and presents a four-metric evaluation framework plus a practical remediation path for path isolation, block alignment, lightweight hit detection, conservative prefetching, and observability.
In large-scale Mixture-of-Experts (MoE) inference serving, engineering teams often add a shared cache to speed up long-context processing. The idea is to store previously computed attention intermediates and reuse them when similar requests arrive. In theory, this is a safe bet: trade one memory read for a full attention computation. Real stress tests, however, can tell the opposite story. After enabling the cache, median latency barely moved, while the slowest 1% of requests (p99) degraded from roughly 3.96 seconds to 17.3 seconds, forcing the team to roll the whole thing back.
This is not an isolated case. It reflects a long-underestimated fact: reading from a cache is not a zero-cost operation. When the cache’s organization granularity, addressing scheme, concurrency path, and scheduling strategy are not aligned with the model structure, it degrades from an “accelerator” into a “tail-latency amplifier.” Using a typical system as a sample, this article breaks down the root causes and offers a reusable evaluation framework and remediation path.
1. Sample System: Model Structure Determines the Cache Cost Model
The sample model is a large-scale MoE architecture running on a single node equipped with 8 high-end accelerator cards. It uses a low-rank compressed attention mechanism: the key-value information of each token is compressed into a shared low-rank vector. As a result, regardless of how many attention heads there are or how the per-head dimension scales, the amount of intermediate data that must be persisted per token stays constant and small.
Under this configuration, with FP8 precision, every 256 tokens are packed into a “block” of about 12.4MB, which works out to only about 48.4KB per token. This number matters: it means the cache’s atomic unit of operation is not a single token but a 12.4MB block. Any reuse must perform addressing, validation, movement, and concatenation at block granularity.
This leads to the first conclusion: the cache cost model is determined jointly by block size × number of accesses × data movement path, not by the saved floating-point operations alone. When blocks are large, accesses are scattered, and hit determination is complex, movement and scheduling overhead can quickly consume the compute savings.
2. Why the Median Stays Flat While p99 Explodes
To understand “flat median, broken tail,” split requests into two categories: reusable and non-reusable. For non-reusable requests, the cache layer only adds a “looked up but missed” path with limited overhead, so the median barely changes. The requests that truly suffer are those that trigger block-level movement and compete with other requests for memory bandwidth and scheduling slots.
The mechanism can be broken into four layers:
- Memory bandwidth contention. Large-model inference is memory-bandwidth intensive. Attention reads and writes, expert weight loading, and activation exchange all compete for the same bandwidth. Cache block movement is an additional large contiguous read; once it overlaps with the main computation, it lengthens the critical path.
- Hit determination and defragmentation. With a block granularity of 256 tokens, request lengths are often not integer multiples, requiring extra boundary handling and fragment merging. If the “similarity” judgment for similar requests relies on complex matching logic, it also introduces unpredictable jitter.
- Scheduling queue effects. If the cache-hit path and the miss path share the same execution queue, long movements block subsequent short requests, creating head-of-line blocking and significantly amplifying tail latency.
- Prefetch and invalidation contention. Prefetching done to improve hit rate becomes pure overhead in low-hit scenarios; invalidation and consistency maintenance also create extra synchronization points under high concurrency.
The illustrative decision logic can be written as:
# Pseudocode: block-level cache hit and movement pathdef lookup_and_load(block_keys, request_len):# 1) Hit determination: match by block key, watch for non-integer-multiple tailhits = [k for k in block_keys if cache.contains(k)]if len(hits) == 0:return None # miss, only pay one lookup cost# 2) Block movement: 256 tokens granularity, 12.4MB/blockchunks = [cache.load(k) for k in hits] # large contiguous read, contends for bandwidthmerged = merge_with_tail(chunks, request_len) # fragment merging and boundary handling# 3) Overlap with main compute determines tail latencyreturn merged
When cache.load contends with the main computation for bandwidth and the queue is not isolated, p99 degradation is almost inevitable.
3. Evaluation Framework: Four Metrics to Quantify Before Enabling a Cache
To avoid “adding a cache on intuition,” make evaluation a quantifiable engineering gate that covers at least the following metrics:
- Effective hit rate and savings ratio: hit rate must be assessed against the request similarity distribution; savings ratio = saved compute time / (movement time + determination time + scheduling wait). If the savings ratio is below 1, the cache is a net negative.
- Bandwidth usage curve: measure peak and average memory bandwidth with the cache on and off, and watch whether it hits the hardware limit.
- Tail-latency breakdown: decompose p99 into queueing, movement, compute, and synchronization to locate the main contributor.
- Block-granularity sensitivity: compare hit rate and movement cost across different block sizes (e.g., 128/256/512 tokens) to find the inflection point.
A simplified decision formula can be written as:
Benefit = hit rate × per-request compute savingsCost = bytes moved / effective bandwidth + determination overhead + queue amplification factor × movement timeThe cache should be on by default if and only if Benefit > Cost
The value of this framework is that it turns “is the cache good” from a subjective judgment into regression-testable metrics. Any change to model structure, precision, or block size can be quickly recomputed.
4. Remediation Path: Turning the Cache from a Drag into an Accelerator
Based on the analysis above, remediation should follow three main lines: reduce movement, isolate paths, and align granularity.
- Path isolation and priority scheduling. Put cache movement and the main computation in separate execution queues, give the main computation higher priority to avoid head-of-line blocking, and apply bandwidth quotas to movement so it cannot squeeze the critical path.
- Align block granularity with request length. Choose block size based on the business request-length distribution to reduce fragment merging caused by non-integer multiples; handle requests shorter than one block with a lightweight path to avoid triggering a full-block movement.
- Lightweight hit determination. Use low-overhead key structures and general techniques such as Bloom filters for pre-filtering, and defer complex matching to reduce determination jitter.
- Conservative prefetching. Enable prefetching only when the historical hit rate is stably above a threshold, and set a bandwidth circuit breaker so it automatically falls back to pass-through mode under low hit rates.
- Built-in observability. Make hit rate, savings ratio, bandwidth usage, and tail-latency breakdown into always-on monitoring and alerting metrics, with automatic rollback of the cache switch on any anomaly.
When deploying in the cloud, you can combine container platforms for canary release and rollback, use monitoring, alerting, and logging services to accumulate metrics, and use object storage to persist block data for cross-instance sharing. However, the shared layer must set bandwidth and concurrency limits to avoid cross-instance contention amplifying tail latency.
5. Conclusion
“Caching is always faster than compute” is a piece of common sense that has been overturned. In low-rank compressed attention, block-granularity movement, and bandwidth-intensive MoE inference scenarios, the cost of reading from a cache must be modeled explicitly. By bringing hit rate, savings ratio, bandwidth, and tail latency into the release gate, and pairing them with path isolation and granularity alignment, a cache can return to its proper place: not a silver bullet enabled by default, but an accelerator validated through quantification.
