When Cache Reads Are Slower Than Compute: The Hidden Cost of Inference Acceleration

    This article examines why adding a shared cache in front of large-scale MoE inference can leave median latency unchanged while pushing p99 latency up more than fourfold. It breaks down the four underestimated costs of cache reads—data movement, addressing and metadata, synchronization, and memory pressure—and explains how caching optimizes the average path while amplifying the worst-case path. It closes with five engineering guidelines for admission control, asynchronous writes, tiered caching, capacity and lease management, and observability, plus a deployment checklist for platform teams.

    1. A Counterintuitive Result: Enabling Cache Quadrupled Tail Latency

    A team was serving inference for a very large Mixture-of-Experts (MoE) model on a single node with 8 high-end accelerator cards. The model and the number of experts were both large. To speed up long-context workloads, they placed a shared cache in front of the service. The idea was to store previously computed attention intermediate results and reuse them when similar requests arrived, avoiding redundant computation.

    The results were disappointing. Median latency barely moved, but the slowest 1% of requests (p99) jumped from 3.96 seconds to 17.3 seconds. The team’s first instinct was to roll the whole thing back.

    The value of this case is that it overturns a long-ignored assumption: reading from a cache also has a cost, and that cost is frequently underestimated. A cache is not a free accelerator. It is a conditional bet—a bet that the hit rate is high enough, that reads are fast enough, and that capacity is large enough. Miss any one of the three conditions, and the gains get eaten by the costs.

    2. Understanding the System: Why “Compute Saved” Is Not “Time Saved”

    To understand the problem, you first have to understand the shape of the workload. The system uses an attention mechanism that compresses each token’s key-value information into a shared low-rank vector. Its key property is this: no matter how many attention heads there are, the amount of intermediate data that must be stored per token is fixed and very small. At FP8 precision, every 256 tokens are packed into one block, and a block is roughly 12.4MB, which works out to about 48.4KB per token.

    These numbers matter because they define the “physical character” of the cache:

    • A single block is not large, so it looks like you can “just store it”;
    • But the number of tokens in long context grows linearly—100,000 tokens is about 400 blocks, nearly 5GB;
    • For a cache to produce a real hit, you often need several consecutive blocks present at once, not just one.

    In other words, the benefit of caching is at the block-sequence level, while the cost is at the block level. This asymmetry is the seed of every problem that follows.

    3. Where Cache Reads Get Slow: Four Underestimated Costs

    3.1 Data Movement: The Bandwidth Wall Between Storage and GPU Memory

    A cache hit does not make computation disappear; it trades “compute” for “movement.” Intermediate results typically sit in host memory or remote storage, and on a hit they must be moved into accelerator memory over a link with limited bandwidth. Compute is bound by compute throughput; movement is bound by bandwidth. They are not the same bottleneck. As concurrency rises, the link is contended by multiple requests, and movement time gets amplified by queuing.

    3.2 Addressing and Metadata: How Many Lookups Does One Hit Take?

    A shared cache needs an index: block hashes, prefix matching, versions and leases, eviction state. Determining a hit is often not a single lookup but a block-by-block prefix comparison. The longer the text, the longer the comparison chain, and this overhead grows with length and frequently sits on the critical path.

    3.3 Synchronization and Consistency: Locks Are the Most Expensive Wait

    Sharing means concurrent reads and writes. To ensure the same prefix is not recomputed and evicted blocks are not read, you need reference counts, leases, or lightweight locks. Under high concurrency, lock contention turns “reading the cache” into “queuing for a lock,” which is the most common amplifier of tail latency.

    3.4 Memory Pressure and Eviction Thrashing: The Cache Gets Evicted Too

    The cache occupies memory, and that memory also has to be shared with the runtime, request queues, and temporary tensors. If capacity planning is too tight, you get thrashing—“stored and immediately evicted, evicted and immediately requested again”—so the hit rate drops instead of rising, while extra bandwidth is consumed.

    A schematic version of the decision logic can be written as:

    1. # Illustrative only: decide whether the cache path is worth taking
    2. def should_use_cache(block_hits, bytes_to_fetch, est_compute_us, link_busy):
    3. if block_hits < MIN_HITS: # too few hit blocks, benefit does not hold
    4. return False
    5. fetch_us = bytes_to_fetch / LINK_BW * (1 + link_busy * QUEUE_FACTOR)
    6. if fetch_us >= est_compute_us: # movement is slower than compute
    7. return False
    8. return True

    4. Why the Median Stayed Flat While p99 Exploded: The Tail Latency Amplification Mechanism

    This is the most memorable mechanism in the article. Caching optimizes the “average path” but hurts the “worst-case path.”

    • The hit path gets faster, but it only covers a minority of requests; the median is diluted by the many misses and shows no visible change;
    • The miss path not only has to compute, but also takes on the extra cost of writing to the cache, index maintenance, and lock waits;
    • A few very long requests hit multiple large blocks at once, and movement plus lock contention stack up, pushing p99 several times higher.

    The conclusion: caches must be evaluated with percentiles and timeout rates, not averages. Looking only at mean latency will almost certainly lead to the wrong decision.

    5. Turning It Into Something That Actually Speeds Things Up: Five Engineering Guidelines

    1. Admission control: If the number of hit blocks is below a threshold, go straight to the compute path; do not let the cache be the default option.
    2. Asynchronize: Move cache writes, index updates, and eviction off the critical path entirely; the read path does only the necessary validation.
    3. Tiered caching: Put hot data in GPU memory, warm data in host memory, and cold data in object storage, tiered by block热度.
    4. Capacity and leases: Set a hard cap and lease expiration for the cache so it does not crowd out the runtime; use batched prefetch to amortize link overhead.
    5. Observability: Turn hit rate, movement time, lock wait, and eviction counts into monitoring and alerting metrics, and keep an evidence trail in a logging service.

    The reasonable expectation after these changes: the hit rate improves, p99 falls back near the baseline or even lower, and the median stays flat. The value of a cache is not “how much you store,” but “how much less travel happens on the critical path.”

    6. A Checklist for Platform Implementers

    When deploying on a container platform or an inference platform, treat the cache as a stateful component to be governed separately: define a clear memory quota, scale it independently, and decouple it from the main inference path; watch percentile latency with a general monitoring and alerting system; estimate capacity as “number of blocks × block size × number of replicas” and leave headroom for the runtime. General capabilities from Baidu AI Cloud (container platform, object storage, logging service, monitoring and alerting) can serve as the hosting layer, but the architectural judgment must come back to the data itself: how large a block is, how many consecutive hits you get, and how busy the link is.

    In one sentence: a cache is not a sufficient condition for acceleration, but an engineering trade that must be measured, rate-limited, and tiered. Calculate the cost of reading the cache first, then decide whether to read it.