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

    This article examines why adding a global shared cache can make tail latency worse instead of better when serving long-context inference on a multi-GPU node. Using a real-world MoE deployment where p99 latency jumped from about 3.96 seconds to 17.3 seconds, it breaks down the structural risks of two-tier caching, the four underestimated sources of cache cost, and practical fixes such as locality-first reads, asynchronous batched writes, admission control, sharding, and observability. Readers will get a reusable, cost-aware methodology for deciding whether caching is worth enabling in tightly synchronized inference architectures.

    1. A Counterintuitive Result: Tail Latency Exploded After Caching Was Enabled

    A team serving inference for a very large Mixture-of-Experts (MoE) model ran into a scenario that upended conventional wisdom. The model ran on a single node with 8 high-performance accelerators, and the primary workload was long-text processing. To reuse attention intermediate results across repeated computation, the team added a global shared cache on top of the existing local cache, expecting similar requests to hit the cache and skip redundant compute.

    The post-launch numbers were discouraging: median latency stayed roughly flat, but p99 (the slowest 1% of requests) degraded from about 3.96 seconds to 17.3 seconds. The team briefly rolled the whole thing back. The episode highlights a key fact: reading from a cache has its own cost, and that cost is significantly amplified when capacity, concurrency, and synchronization constraints stack up. When the cache read path becomes a new serialization bottleneck, it delivers queuing rather than speedup.

    Rather than restating the details of any single paper, this article abstracts the problem into a general engineering methodology for inference caching, so developers can spot the risks early in similar architectures.

    2. Understanding the Workload: Why Long-Context Prefill Is Cache-Unfriendly

    2.1 Compression and Blocking of Attention Intermediate Results

    Modern large models often use low-rank compressed attention to reduce the storage overhead of the key-value cache. The core idea: regardless of how many attention heads there are, the intermediate state that must be stored per token is compressed into a fixed, small low-rank vector. At FP8 precision, engineering practice typically packs several consecutive tokens into a “block” for unified management. With 256 tokens per block, a single block can be kept around 12.4MB, averaging about 48.4KB per token.

    This characteristic has two consequences:

    • A block is not small, so a cache read is a real bandwidth and memory-copy cost, not as cheap as a pointer lookup.
    • The block is the minimum unit for caching and transfer, so growing request length linearly amplifies the amount of data that must be moved.

    2.2 Strong Synchronization Constraints in Context-Parallel Prefill

    Long-context prefill is compute-heavy, so context parallelism is often used to split an input across multiple GPUs for simultaneous computation, after which the GPUs exchange intermediate results over the intra-node network so that each one holds the full context. Here the 8 GPUs behave like meshed gears: if any one waits, all the others spin idle.

    Under this tightly synchronized structure, tail latency is multiplicative rather than additive: if a cache read slows down even one GPU, the effective throughput of the entire node drops.

    2.3 Structural Risks of a Two-Tier Cache

    A typical design pairs an L1 local memory cache (fast, small, private) with an L2 shared key-value store (large capacity, reusable across engines, like a public library). The risk concentrates in L2: all inference instances share the same ledger, and both writes and reads go through the same service. When 8 GPUs write concurrently and only one “accountant” records entries, queuing is inevitable. This explains why the median stayed flat while p99 spiked—most requests never triggered contention, while a few hit write amplification and lock contention.

    3. Root Causes: Four Underestimated Sources of Cache Cost

    1. Write amplification and consistency overhead: the shared tier must maintain key metadata, expiration, and eviction, so a single write can trigger multiple internal operations.
    2. Network and serialization cost: accessing shared storage across processes requires serializing large tensors, and 12.4MB-scale blocks are not negligible over a network round trip.
    3. Synchronization blocking: context parallelism turns a single slow point into a global slowdown, amplifying cache jitter into node-level jitter.
    4. Insufficient hit payoff: long-text requests share similar prefixes but differ greatly in their suffixes, so the hit rate is limited and the gains cannot cover the cost.

    The following pseudocode expresses a “cost-aware cache decision”:

    1. def should_use_cache(block, hit_prob, compute_cost_ms, fetch_cost_ms):
    2. # Use the cache only when the expected saving exceeds the expected read cost
    3. expected_gain = hit_prob * compute_cost_ms
    4. expected_cost = (1 - hit_prob) * 0 + fetch_cost_ms
    5. return expected_gain > expected_cost * SAFETY_FACTOR

    4. The Fix: Turning the Cache from a Drag into an Asset

    • Tiering and locality: prefer L1 hits and use L2 only for asynchronous backfill; avoid synchronous access to the remote shared tier on the critical path.
    • Asynchronous and batched writes: move shared-tier writes to background batch submission to reduce lock contention and write amplification.
    • Admission control and rate limiting: disable caching or fall back to a pure compute path for requests with low hit probability or a large number of blocks.
    • Sharding and multiple writers: shard the shared key space by prefix hash to eliminate the single “accountant”.
    • Compressed transfer and zero-copy: apply lightweight compression to blocks and use shared memory mapping to reduce serialization overhead.
    • Observability: separately monitor hit rate, read-latency distribution, write-queue length, and synchronization wait time to locate the source of tail latency.

    5. Engineering Guidelines and Conclusion

    Three guidelines help decide whether caching is worth enabling. First, the cost of reading from the cache must be modeled explicitly. Second, in a tightly synchronized parallel architecture, any single-point jitter is amplified, so evaluate with tail latency rather than the mean. Third, treat the shared tier as a scarce resource by default, and protect the critical path with asynchronous I/O, sharding, and rate limiting. On general-purpose cloud capability stacks such as Baidu AI Cloud, the observability and elastic governance described above can be built by combining monitoring and alerting, logging services, and container platforms.