Why Caching Can Be Slower Than Computing: The Hidden Cost of Inference Acceleration
This article examines a counterintuitive result from building inference services for a large-scale Mixture-of-Experts (MoE) model: after adding a shared cache for attention intermediate results, median latency barely improved while p99 tail latency worsened from 3.96 seconds to 17.3 seconds. It explains how model structure and hardware coupling determine cache economics, identifies the structural bottlenecks of a two-tier cache where the shared layer becomes a serialization point, outlines a root-cause diagnosis method based on layered timing and net-benefit accounting, and presents five engineering remedies: asynchronous non-blocking reads and writes, batched and coalesced writes, sharding with fine-grained locks, admission and eviction policies, and observability with capacity planning. Readers will learn how to model cache cost explicitly and keep caching a measurable, rollback-safe acceleration technique.
1. A Common Assumption Overturned: Why Tail Latency Spiked After Enabling Cache
A team building inference services for a very large Mixture-of-Experts (MoE) model ran into a counterintuitive result. The model was deployed on a single node with 8 high-end accelerator cards. To speed up long-text processing, the system added a shared cache layer that stored previously computed attention intermediate results, so that similar incoming requests could reuse them instead of recomputing.
The post-launch numbers were disappointing: median latency barely improved, while tail latency for the slowest 1% of requests (p99) deteriorated from 3.96 seconds to 17.3 seconds. The team briefly rolled the feature back entirely.
The core conclusion of this practice write-up is a single sentence: reading from a cache is not a zero-cost operation, and its cost is routinely underestimated during system design. When the overhead of cache writes, lookups, synchronization, and consistency maintenance exceeds the computation it saves, the cache degrades from an “accelerator” into a “bottleneck amplifier.”
2. Understand the Workload First: Model Structure Determines Cache Economics
Deciding whether a cache is worthwhile requires first understanding how the model couples with the hardware.
Compressed attention reduces per-request cache volume. This class of model uses a low-rank compressed attention mechanism that compresses each token’s key-value information 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. At FP8 precision, every 256 tokens are packed into one block of roughly 12.4MB, or about 48.4KB per token. The cache “granularity” is therefore the block, not the individual token.
Long-text prefill is split and parallelized. To reduce prefill time for long texts, the system uses context parallelism: a long text is split into segments assigned to multiple cards for simultaneous computation, after which the cards exchange and synchronize intermediate results over intra-node communication so that every card holds the full context.
Synchronization barriers amplify single-point jitter. The 8 compute units within one node are tightly coupled and must communicate to align at every step; if any single unit is slowed down, the other seven must wait. This structure is extremely sensitive to “slow operations,” and any blocking wait is amplified into a global stall.
3. Structural Flaws of the Two-Tier Cache: The Shared Layer Becomes a Serial Bottleneck
The system’s cache has two tiers: a first-tier cache near the compute units, located in local memory, which is fast but limited in capacity; and a second-tier cache in an external key-value store, which is large and shared by all inference engines, much like a public library.
The problem is concentrated in the second tier. An analogy: a chain of bubble tea shops where each store keeps its own books (the first-tier cache), but so that headquarters can audit everything centrally, all transactions must be written into a single master ledger (the second-tier cache) maintained by only one accountant. At peak time, eight stores write simultaneously and all queue up at that one accountant.
The technical causes come down to four points:
- Write amplification: every computation of every block may trigger a remote write, so the number of write requests far exceeds the benefit from cache hits.
- Serialization: metadata operations on the shared store, or a single-threaded event loop, form a queue under high concurrency.
- Blocking calls: compute threads synchronously wait for remote reads and writes to return, occupying execution slots that could have been used for computation.
- Consistency overhead: when multiple engines share the same namespace, key collisions, invalidation, and version checks add further round trips.
4. Root-Cause Diagnosis: Turning “It Feels Slow” into Explainable Metrics
To reproduce and locate this class of problem, add instrumentation and run experiments in the following order:
Layered timing. Measure compute time, first-tier cache hit time, second-tier cache read/write time, and communication synchronization time separately, instead of looking only at end-to-end latency.
Hit rate and benefit accounting. Introduce two quantities, “compute time saved” and “new cache overhead added,” and compute the net benefit; if the net benefit is negative, disable the cache by default.
Tail latency attribution. Trace the p99 requests end to end to confirm whether the blocking point is a remote write, lock waiting, or a synchronization barrier.
Illustrative pseudocode (conveying the idea only):
# Illustrative only: cache access with admission control and asynchronydef lookup_or_compute(block_id, ctx):t0 = now()v = l1.get(block_id) # local memory, nanosecond to microsecond scaleif v is not None:metrics.inc("l1_hit"); return vif should_admit(block_id): # admission control: cache only high-reuse blocksv = l2.async_get(block_id) # non-blocking, give up on timeoutif v and now() - t0 < BUDGET:metrics.inc("l2_hit"); return vv = compute(block_id, ctx) # actual computationl1.put(block_id, v)if should_admit(block_id):l2.async_put(block_id, v) # asynchronous batched write, does not block computereturn v
5. Five Categories of Changes: Making the Cache Actually Faster
Asynchronous and non-blocking reads and writes. Compute threads must not synchronously wait on the remote cache; adopt a “return the compute result first, backfill asynchronously in the background” strategy, with timeouts and fallback, so that cache failures do not affect the main path.
Batching and coalesced writes. Merge writes of multiple blocks in the same batch into a single remote operation to reduce request count and round trips; for high-frequency blocks, use a write-coalescing window, trading a small amount of consistency for throughput.
Sharding and fine-grained locks. Shard by block identifier hash to avoid a global single-point serialization; refine lock granularity to the shard or object level to reduce mutual waiting.
Admission and eviction policies. Cache only blocks with a high probability of reuse (such as system prompts, long-document prefixes, and stable context), and skip one-off content entirely; use an eviction policy based on reuse count and size to prevent cache thrashing.
Observability and capacity planning. Bring cache hit rate, net benefit, remote read/write latency distribution, and queue length into monitoring and alerting; in capacity planning, treat the cache as a “resource with a cost” rather than a free acceleration layer. If you rely on general-purpose cloud capabilities, you can combine object storage, message queues, logging services, and monitoring alerts to build a closed loop for asynchronous backfill and observability.
6. Engineering Conclusion
A shared cache is not a free lunch. In a synchronously parallel, tail-latency-sensitive inference system, the cost of reading from cache must be modeled explicitly: caching is justified only when the “compute time saved” is stably greater than the “new cache and synchronization overhead added.” Through asynchrony, batched writes, sharded locks, admission control, and solid observability, a team can pull p99 back from catastrophic jitter into a controllable range and restore the cache to its proper role: a measurable, rollback-safe, optimizable acceleration technique.
