When Caching Is Slower Than Computing: The Hidden Cost of Inference Acceleration

    This article examines a counterintuitive problem in large-scale MoE inference: enabling a shared cache left median latency unchanged while pushing P99 latency from 3.96 seconds to 17.3 seconds. It breaks down the workload, the two-tier cache design, and four hidden costs of cache reads—metadata serialization, network round trips, synchronization barriers, and low hit rates—then presents practical fixes such as moving reads off the critical path, sharding, admission and eviction policies, backpressure, topology alignment, and observability. Readers will learn how to decide whether caching is actually worth it.

    1. A Common Assumption Turned Upside Down: Tail Latency Spiked After Caching Was Enabled

    A team building an inference service for a very large Mixture-of-Experts (MoE) model ran into a counterintuitive result. The model was large enough to run on a single node equipped with eight accelerator cards. To speed up long-context processing, the team added a shared cache layer that stored previously computed attention intermediate results, hoping to reuse them when similar requests arrived and skip redundant computation.

    The post-launch numbers were disappointing. Median latency barely improved, while the slowest 1% of requests (P99 latency) jumped from 3.96 seconds to 17.3 seconds—roughly 4.4x higher. The team briefly rolled back the entire caching feature.

    The core lesson can be stated in one sentence: reading from a cache is itself a compute and communication operation with its own cost, and once capacity, concurrency, and topology amplify that cost, it can far exceed the compute it saves. A cache is not a free accelerator; it is a trade that must be calculated carefully.

    2. Understand the Workload First: Model Structure and the Memory/Communication Ledger

    Diagnosing the problem requires a clear picture of what the system actually looks like.

    2.1 Low-Rank Compressed Attention

    The system uses an attention design that compresses key-value information into shared low-rank vectors. Its defining property is that the amount of intermediate data stored per token is fixed and small, regardless of how many attention heads there are. In this scenario, with 8-bit floating point precision, every 256 tokens are packed into one “block” of roughly 12.4 MB, which works out to only about 48.4 KB per token.

    That smallness cuts both ways. It makes the cache look cheap, so the team was inclined to “store more and reuse more.” But once concurrency rises, the small per-token footprint is quickly offset by the number of requests and synchronization overhead.

    2.2 Context Parallelism During Prefill

    Prefilling long contexts is extremely compute-intensive, so the team split a long input across multiple cards for parallel processing. Afterward, each card had to exchange intermediate results over the intra-node network before it could hold the complete context.

    This means the latency of a single request is determined by the slowest card. The eight cards mesh like gears: if one link waits, the other seven spin idle. Any extra waiting point introduced by the cache gets multiplied by this synchronization structure.

    2.3 Structural Flaws in the Two-Tier Cache

    The cache was designed with two tiers:

    • L1: local memory close to the accelerators—fast but small;
    • L2: an external key-value store—large capacity, shareable across multiple inference engines, similar to a “public library.”

    The trouble was in L2. A useful analogy is a chain of bubble tea shops. Each store keeps its own books quickly (L1), but headquarters requires every transaction to be rolled into one master ledger (L2), and only one accountant maintains that ledger. At peak hours, all eight stores write at once and queue up at the accountant’s desk. The capacity benefit of sharing is eaten by the serialization cost of a single write point.

    3. Root Cause Breakdown: Four Hidden Costs of Reading the Cache

    3.1 Serialized Metadata and Write Hotspots

    Metadata operations, lock contention, and a single-threaded write path in the shared store force concurrent writes to queue. The more requests, the longer the queue, and tail latency degrades nonlinearly. This explains “unchanged median, exploding P99”: only the small subset of requests that happen to hit the cache or participate in synchronization gets held up.

    3.2 Network Round Trips and Serialization Overhead

    Fetching one block from L2 requires a cross-process or even cross-node round trip, plus serialization/deserialization, memory copies, and validation. With a 12.4 MB block, these seemingly tiny constants accumulate into second-level latency under high concurrency.

    3.3 The Amplification Effect of Synchronization Barriers

    Under context parallelism, the cache read sits on the critical path. If any one rank waits on L2, all ranks wait together. A single slow query locally becomes a full-request stall.

    3.4 Low Hit Rate and Negative Optimization

    If request similarity is low, the hit rate stays limited. The system pays the full cost of writing, reading, and maintaining consistency while getting back only modest savings. At that point, the cache is pure negative optimization.

    4. The Fix: Putting the Cache Back in the Accelerator Role

    4.1 Move Cache Reads Off the Critical Path

    The core principle is compute first, store in the background. Replace synchronous reads with asynchronous prefetch and speculative execution. On a miss, enter the normal compute path immediately and never let a request idle while waiting on storage.

    1. if l1_hit(block): # local hit, zero network cost
    2. reuse(block)
    3. else:
    4. task = launch_compute(block) # start computing immediately
    5. prefetch_from_l2_async(block) # fetch in the background, non-blocking
    6. if prefetch_done_before_need(block):
    7. reuse(block) # reuse only if it arrived early enough
    8. else:
    9. await task # otherwise use the compute result

    4.2 Sharding and Hotspot Removal

    Shard L2 by block hash across multiple storage instances to avoid single-point serialization. Use batched, coalesced writes with local staging to reduce metadata contention. In the analogy, replace “one accountant” with “several accountants each handling their own books,” and let stores record receipts first and reconcile them in a nightly batch.

    4.3 Tiered Admission and Eviction Policies

    • Cache only blocks with a high reuse probability (for example, system prompts, long-document prefixes, stable context);
    • Give each tier its own capacity and eviction policy so large blocks do not evict small ones;
    • Add a combined frequency and recency score to keep one-off content from polluting the cache.

    4.4 Backpressure, Rate Limiting, and Timeouts

    Set an independent concurrency limit and timeout for the cache channel; on timeout, fall back to the compute path. When the L2 queue depth exceeds a threshold, automatically lower write priority to protect the main path.

    4.5 Align with the Parallelism Topology

    Align cache shards with the context-parallel partitioning so each rank interacts only with its “nearest” shard, reducing cross-node traffic and synchronization waits.

    4.6 Observability First

    At minimum, collect hit rate, read latency distribution (P50/P95/P99), write queue depth, per-block transfer time, and the extra waiting time caused by the cache. Without these metrics, neither the benefits nor the costs of caching can be attributed.

    5. A Methodology: How to Decide Whether to Cache

    1. Calculate the break-even point: compute time saved × hit rate must clearly exceed read latency + write amplification + synchronization wait.
    2. Look at tail latency, not the mean: averages hide queueing and synchronization problems; P99 is the truth of user experience.
    3. Default to asynchronous: treat any external read on the critical path as a risk point.
    4. Be cautious with sharing: cross-engine sharing increases capacity but introduces consistency and hotspot costs, and requires sharding and rate limiting.
    5. Roll out in small steps: gate with a switch, ramp by traffic percentage, and keep one-click rollback available.

    6. Conclusion

    “Caching is always faster” is a widely assumed common belief, but in inference systems that are very large, strongly synchronized, and highly concurrent, it can completely reverse. A mature cache design is not about packing more data into faster media. It is about calculating the cost structure clearly, moving reads off the critical path, and breaking up shared hotspots. Once a team learns to put a price on “reading the cache,” the cache earns the name “accelerator.”