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

    This article examines a counterintuitive result in large-scale Mixture-of-Experts (MoE) inference: adding a shared prefix cache left median latency unchanged while pushing p99 latency from roughly 3.96 seconds to 17.3 seconds. It breaks down five underestimated costs of cache reads—data movement, addressing and metadata, cross-device synchronization, queuing and scheduling, and fragmentation—then presents a three-layer observability model (request, cache, and resource layers) for identifying negative-return cache hits. Finally, it covers practical fixes including admission control, decoupling reads from compute into separate queues, asynchronous prefetching with tiered caching, cache-aware batching, block granularity tuning, and eviction based on time saved rather than hit counts.

    1. A Common Assumption Turned Upside Down: Cache Does Not Equal Speed

    A team serving inference for a very large Mixture-of-Experts (MoE) model ran into a counterintuitive result. The hardware was a single node with eight high-bandwidth accelerator cards, the model used a compressed key-value attention mechanism, and long-context requests made up a large share of traffic. To reuse computation across repeated prefixes, the team added a shared cache layer, expecting similar requests to hit it and skip redundant work.

    The production numbers were surprising: median latency barely moved, while the slowest 1% of requests (p99) degraded from about 3.96 seconds to 17.3 seconds. The team’s first instinct was a full rollback. The postmortem came down to a single conclusion: reading from a cache has a cost, and that cost has been severely underestimated.

    The baseline to establish is this: the benefit of a cache is the computation you avoid, and the cost is the extra data movement, addressing, synchronization, and queuing. When the cost is amplified beyond the benefit, a cache stops being an accelerator and becomes a speed bump. On tail metrics like p99, any additional resource contention gets magnified into second-level jitter.

    2. Understanding the Workload: Why This System Is So Cache-Sensitive

    Diagnosing the problem requires understanding how the model and hardware interact.

    • Compressed attention creates small blocks: Compressed key-value attention projects each token’s key-value information into a shared low-rank vector, so a request’s cache footprint stays relatively fixed and small regardless of the number of attention heads. In the scenario described here, at FP8 precision every 256 tokens are packed into one block of roughly 12.4MB, or about 48.4KB per token.
    • Long contexts inflate block counts linearly: Each block is small, but long contexts increase the block count quickly. A request with hundreds of thousands of tokens can leave a cache footprint on the order of several GB.
    • MoE shares memory and bandwidth: Dynamic weight loading from expert routing competes with cache movement for memory bandwidth and on-chip resources.
    • Queuing under high concurrency: When cache reads and compute tasks contend for the same queue, tail requests are the most likely to be overtaken and blocked.

    Together, these four factors mean the cache is not “free secondary storage” but a competitor tightly coupled to the main compute path.

    3. Where the Cache Slows Down: Five Underestimated Costs

    3.1 Data Movement: Bandwidth Is Scarce

    A cache hit is not free. Moving several GB of key-value blocks from the cache medium to the compute units consumes memory bandwidth. When multiple requests hit at the same time, bandwidth is split, effective per-request bandwidth drops, and read time stretches out.

    3.2 Addressing and Metadata: Small Operations, Large Overhead

    A cache has to maintain block indexes, hashes, reference counts, and eviction metadata. Under high concurrency, lock contention in metadata structures, hash collisions, and directory growth turn “look up the cache once” into a hidden tax ranging from microseconds to milliseconds.

    3.3 Synchronization and Consistency: Invisible Fences Across Devices

    On a multi-card node, cached blocks may be spread across several devices. A hit requires cross-device alignment and visibility synchronization, and every synchronization is a global fence that stalls all waiters at once.

    3.4 Queuing and Scheduling: The Tail Gets Amplified

    If cache reads and decode compute share an execution queue, read tasks block compute tasks, and vice versa. Median requests are relatively insensitive because of large sample size and high interleaving probability; p99 requests land exactly when resources are tightest and get amplified into second-level latency.

    3.5 Fragmentation and Jitter: The Illusion of Hit Rate

    A fixed block granularity (such as 256 tokens) creates internal fragmentation, and insufficient prefix similarity produces hits that look valid but do no useful work. If hit rate is measured only at the request level, it hides ineffective block-level movement and creates the illusion of “plenty of hits, no time saved.”

    4. Diagnosis: Opening the Black Box with Layered Metrics

    Do not look at end-to-end latency alone. A three-layer observability system is recommended:

    • Request layer: p50/p95/p99, input length distribution, hit rate (tracked separately at request and block level).
    • Cache layer: bytes read per block, average and tail read latency, metadata lock wait, eviction rate, fragmentation rate.
    • Resource layer: memory bandwidth utilization, queue depth, number of cross-device synchronizations and total wait time.

    A simple decision rule:

    1. if compute time saved by the hit < read movement time + addressing time + synchronization wait + queuing overhead:
    2. the hit is a "negative-return hit"

    Measuring the share of negative-return hits usually explains why p99 degrades: tail requests are exactly where negative-return hits cluster.

    5. The Fix: Turning Negative Optimization into Real Acceleration

    5.1 Admission Control: Not Every Request Should Read the Cache

    For requests whose estimated read cost exceeds their compute cost, skip the cache entirely. Input length, estimated block count, and current bandwidth headroom can all serve as admission criteria.

    1. admit = (estimated_read_bytes / effective_bandwidth) < (estimated_compute_time * α)

    Here α is a safety factor; an initial value of 0.7–0.9 is reasonable, then tune it against production data.

    5.2 Decouple Compute and Reads: Separate Queues and Priorities

    Put cache reads in a dedicated queue, separated from decode compute, and give tail requests priority so they are not drowned out by large batches of hits. Where necessary, add a timeout and fallback path for read tasks: on timeout, fall back to recomputation.

    5.3 Asynchronous Prefetch and Tiered Caching

    Keep hot prefixes on the highest-bandwidth tier and push cold blocks down; use asynchronous prefetch to move data before the request arrives, hiding synchronization waits on the hit path.

    5.4 Batch Coordination: Match Hits to Batch Size

    Continuous batching changes batch composition dynamically. If a cache hit makes sequence lengths within a batch too uneven, padding waste follows. The scheduler should be cache-hit aware and group requests that share a prefix into the same batch to raise reuse density.

    5.5 Block Granularity and Layout Tuning

    Balance fragmentation against addressing cost: blocks that are too large waste bandwidth, blocks that are too small amplify metadata overhead. Adjust packing granularity adaptively based on the length distribution, and align memory layout to reduce cross-device synchronization.

    5.6 Eviction Policy and Hit Rate Definition

    Evict based on time saved rather than hit count, and report block-level hit rate to expose ineffective movement.

    6. Engineering Checklist

    • Build a dashboard linking p99 to the negative-return hit ratio, with alert thresholds.
    • Ship an admission control switch with gradual rollout by tenant or length bucket.
    • Physically isolate the read queue from the compute queue and configure timeout fallback.
    • Introduce asynchronous prefetch, validating gains first with offline traffic replay.
    • Make the scheduler cache-hit aware to improve prefix aggregation within batches.
    • Review block granularity and fragmentation rate regularly, and adjust dynamically.

    7. Conclusion

    “Caching is always faster” is a widely assumed default, but in large-scale MoE, long-context, high-concurrency inference, the movement, addressing, synchronization, and queuing costs of reading a cache get significantly amplified and can outweigh the computation it saves. Real acceleration is not “add a cache layer” but making every hit net positive: admission control to filter out negative-return requests, queue decoupling to protect tail latency, asynchronous prefetch to hide movement cost, and scheduling coordination to raise reuse density. Only when the cache is reworked this way does p99 actually drop—and only then does the common assumption hold again.