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

    This article examines a counterintuitive production incident where adding a shared cache to a large-scale MoE inference system left median latency unchanged but pushed p99 latency from 3.96 seconds to 17.3 seconds. It breaks down the four hidden bills behind cache reads—bandwidth, metadata granularity, admission control, and tail latency from synchronous writes—and presents the fixes that restored performance: larger blocks, reuse-probability admission with LRU/LFU eviction, asynchronous writes, zero-copy reads with prefetching, and observability for hit rate, bandwidth saturation, allocation latency, and write backlog. It also outlines the boundaries where disabling the cache is the better choice and a practical checklist for inference teams.

    1. A Counterintuitive Production Incident

    A team serving inference for a very large Mixture-of-Experts (MoE) model ran into a result nobody expected. The system ran on a single node equipped with 8 high-end accelerator cards. To speed up long-context processing, the engineers added a shared cache layer that stored previously computed attention intermediate results, hoping to reuse them when similar requests arrived and skip redundant computation.

    After the feature flag was turned on, median latency barely improved. But the slowest 1% of requests—p99 latency—jumped from 3.96 seconds to 17.3 seconds. The team ended up fully rolling back the caching feature.

    The core takeaway of this postmortem is a single sentence: reading from a cache is not free, and that cost is routinely underestimated during capacity planning. When the cost of reading exceeds the cost of recomputing, a cache stops being an accelerator and becomes a speed bump.

    2. Understanding the Workload: Model Architecture and the Memory Ledger

    Diagnosing the problem starts with understanding the shape of the system.

    The model’s attention mechanism uses a low-rank compression approach commonly known as MLA (Multi-head Latent Attention): the key-value information of each token is compressed into a shared low-rank vector, so the amount of intermediate data stored per token stays fixed and small regardless of the number of attention heads.

    In the scenario under review, the system used FP8 precision and packed every 256 tokens into a “block” of roughly 12.4MB—about 48.4KB per token. This ledger matters:

    • A single request of 100,000 tokens means roughly 4.6GB of intermediate data.
    • A 30% cache hit rate would theoretically save a large amount of recomputation.
    • But what is saved is compute time, while what is paid is transfer time + scheduling time + contention time.

    The complication is that expert routing in an MoE architecture is data-dependent. Different requests activate different combinations of experts, so cache reuse also carries hidden overhead for routing and layout conversion. A gap opens up between the theoretical benefit and the engineering reality.

    3. Root Cause: Four Hidden Bills Behind Cache Reads

    3.1 The Bandwidth Bill: Moving Data Costs More Than Computing

    Attention computation is highly parallel and compute-intensive. A cache read, by contrast, is essentially a large-scale transfer of data from device or host memory. When block granularity is small and request concurrency is high, transfer bandwidth saturates quickly and read queueing time is amplified. The compute units end up waiting for data instead of computing on it.

    3.2 The Granularity Bill: Small Blocks Cause Metadata Explosion

    A 12.4MB block may not look small, but under high concurrency, hundreds or thousands of small blocks are being allocated, freed, and compared at the same time. Metadata management and address translation overhead rise sharply, and lock contention plus allocator jitter push tail latency even higher.

    3.3 The Admission Bill: A Cache Without Eviction Is a Slow Self-Lock

    The original implementation had no admission or eviction control. Cold data and hot data were mixed together, so the hit rate stayed low while bandwidth and device memory were continuously consumed—the worst possible combination of holding resources without doing useful work.

    3.4 The Tail Latency Bill: Synchronous Writes Amplify Jitter

    Cache writes were executed synchronously on the critical path of each request. As soon as one block became slow to write, the entire batch of requests was held back, and p99 blew up. The median still looked fine because most requests never actually hit the cache or triggered a write.

    4. The Fix: Making the Cache Fast Again

    4.1 Increase Block Granularity to Amortize Metadata Cost

    Raising the block size from 256 tokens to 1024–2048 tokens increases per-block size while reducing the number of blocks by an order of magnitude, significantly easing metadata and lock contention. Illustrative configuration logic:

    1. # Pseudocode: dynamically adjust block granularity based on load
    2. def choose_block_size(qps, avg_seq_len, mem_budget):
    3. if qps > 200 and avg_seq_len > 32000:
    4. return 2048 # high concurrency + long context: prioritize amortizing metadata
    5. if mem_budget < 0.3:
    6. return 1024 # tight memory budget: compromise
    7. return 512

    4.2 Admission Control: Cache Only Blocks Worth Caching

    Introduce a reuse-probability-based admission policy: a prefix is allowed into the cache only if it has been accessed more than a threshold number of times within a sliding window. Combined with segmented LRU/LFU eviction, this gives bandwidth to the blocks that are genuinely hot. In practice, the hit rate needs to rise from below 30% to above 50% before the savings are large enough to cover the transfer cost.

    4.3 Make Writes Asynchronous and Move Them Off the Critical Path

    Change cache writes to asynchronous background flushes so that returning a response is not blocked by a write. Pair this with batched, coalesced writes to reduce small I/O. The critical path keeps only “read on hit and use it”; on a miss, recompute directly.

    4.4 Zero-Copy Reads and Prefetching

    Use zero-copy views for hit blocks to avoid an extra memory copy. For predictable next blocks, add lightweight prefetching so transfer latency is hidden behind compute latency.

    4.5 Observability: Make the Hidden Bills Visible

    Four categories of metrics must be monitored: hit rate, read bandwidth saturation, block allocation/free latency, and write queue backlog. Without these metrics, cache optimization is guesswork. Build separate dashboards for p50/p95/p99, and run a canary comparison with the cache flag on and off.

    5. Results and Boundaries After the Fix

    After the changes, median latency stayed flat, and p99 fell from 17.3 seconds back to roughly the original 3.96 seconds, while delivering meaningful recomputation savings under long-context traffic with high prefix overlap. The boundary to emphasize: caching is not a cure-all. When prefix overlap in the traffic is low, or when block granularity does not match available bandwidth, turning the cache off is often the optimal choice.

    6. A Checklist for Engineering Teams

    • First, calculate the bandwidth bill: per-token intermediate data size × concurrency × number of blocks.
    • Before any cache goes live, define admission and eviction policies.
    • Always make writes asynchronous; never flush to disk or device memory synchronously on the critical path.
    • Use p99, not the median, as the acceptance criterion for a cache.
    • Set up flag-level canary and rollback plans, and keep a one-switch kill capability.

    7. Conclusion

    “Caching is always faster than computing” is a piece of common sense that this incident overturned. Real acceleration comes from precisely modeling the cost structure: a cache only pays off when the combined cost of reading, scheduling, and contention is lower than the cost of recomputation. For teams building inference services, making the hidden bills visible is the first—and most important—step toward avoiding the trap of “the more we optimize, the slower it gets.”