When Caching Is Slower Than Computing: The Hidden Cost of Inference Acceleration
This article examines a counterintuitive production incident where adding a shared cache to a large-scale MoE model inference service worsened p99 latency from 3.96s to 17.3s. It breaks down why MoE and MLA-style attention make serving sensitive to data movement, presents a cost model that treats cache reads as a real computation, identifies four root causes of tail-latency spikes, and outlines a redesign based on tiering, asynchronous prefetching, and graceful degradation, along with rollout and acceptance metrics.
1. A Counterintuitive Production Incident
A team was serving inference for a very large Mixture-of-Experts (MoE) model on a single node with 8 high-performance accelerators. To reduce response time for long-context requests, they added a shared cache at the service layer to store previously computed attention intermediate results, hoping to reuse them when requests were similar and skip redundant computation.
The post-launch data contradicted expectations: median latency barely improved, while the slowest 1% of requests (p99) degraded from 3.96 seconds to 17.3 seconds. The team initially rolled everything back. The retrospective produced a single conclusion: reading from a cache also has a cost, and that cost has long been severely underestimated.
Using this scenario as a blueprint, this article abstracts a general methodology for deciding whether to cache, quantifying cache-read overhead, and turning a cache that drags performance down into a genuine acceleration layer.
2. Understanding the Workload: Why This Scenario Is Special
The MoE architecture assigns different parameter shards to different tokens, allowing the total parameter count to scale without significantly increasing per-token computation. The tradeoff is higher memory footprint and communication complexity, which makes the serving side extremely sensitive to data movement.
The attention mechanism used by this service follows a low-rank compression approach (commonly referred to in the industry as an MLA-style scheme): each token’s key-value information is compressed into a shared low-rank vector, so the amount of intermediate data stored per token stays constant and small regardless of the number of attention heads. Under FP8 precision, every 256 tokens are packed into one block of roughly 12.4MB, or about 48.4KB per token.
These two numbers matter: a single block is not large, but long contexts rapidly multiply the block count. A 32K context is about 128 blocks and roughly 1.6GB; with dozens of concurrent requests, cache capacity and bandwidth pressure scale up together.
3. Cost Model: Treat Reading the Cache as a Real Computation
Let:
C_compute: time to recompute the block’s attention;C_lookup: time for prefix matching/index lookup;C_transfer: time to move data from the cache medium to GPU memory;C_host: software overhead such as serialization, validation, and lock contention.
Caching yields a net gain only when C_lookup + C_transfer + C_host < C_compute. In practice C_transfer is often ignored: if the cache resides in remote or host memory, PCIe/network bandwidth becomes a hard ceiling.
Illustrative decision logic:
def should_use_cache(block, ctx):est_compute = ctx.flops(block) / ctx.effective_tflopsest_load = block.size / ctx.min(ctx.pcie_bw, ctx.net_bw)overhead = ctx.lookup_cost + ctx.serialize_cost + ctx.lock_waitreturn est_load + overhead < est_compute * ctx.safety_factor
A safety_factor of 0.7–0.8 is recommended to leave headroom for jitter.
4. Four Root Causes of p99 Explosions
- Medium mismatch: the cache sits in host memory or remotely, so a hit adds extra hops.
- Long-tail amplification: long contexts mean more blocks, and per-request transfer volume grows linearly until it hits the bandwidth ceiling.
- Lock and queue coupling: a global lock or single queue makes hit requests wait, stacking latency.
- Eviction thrashing: insufficient capacity causes frequent swap-in/swap-out, degrading the cache into a “negative optimization layer.”
5. Redesign: Tiered, Asynchronous, Degradable
- Tiered cache: L1 in GPU memory (small capacity, lowest latency), L2 in host memory, L3 on local high-speed storage; migrate adaptively by block热度.
- Asynchronous prefetch: once a hit is determined, start the transfer immediately and overlap it with the scheduling phase to hide
C_transfer. - Sharding and lock-free indexing: shard by prefix hash to reduce lock contention; for read-heavy, write-light workloads, use read-only snapshots.
- Admission and degradation: bypass the cache when estimated gain is below a threshold; automatically fall back to pure computation when bandwidth or queue depth exceeds a threshold.
- Observability: instrument hit rate, bytes transferred, queue time, and eviction count separately, and build a percentile-latency dashboard with logging and alerting.
Pseudocode example:
if hit := index.probe(prefix_hash):task = prefetch_async(hit, to="hbm")schedule_other_work()block = task.wait(timeout=ctx.budget)if block is None:block = compute(prefix) # degradation pathelse:block = compute(prefix)cache.put_async(block, tier=choose_tier(block))
6. Rollout Strategy and Acceptance Metrics
Validate on shadow traffic first, then ramp gradually. Core acceptance items: p50/p95/p99 latency, hit benefit ratio (compute time saved / total transfer time), bandwidth utilization, and eviction rate. If p99 does not improve while p50 improves markedly, transfer and queuing are usually the bottleneck, and tiering plus asynchrony should be prioritized over further cache expansion.
7. Conclusion
A cache is not a free accelerator but a resource trade with a cost. Account for C_transfer and software overhead before deciding to serve a hit; use tiering, asynchrony, and degradation to hold down tail latency, and only then does a shared cache turn from “common sense” into real performance gains.
