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

    This article examines why adding a shared prefix cache in front of a large MoE model made tail latency worse instead of better. It breaks down the memory layout of low-rank compressed attention, the four mechanisms behind the slowdown, a simple breakeven model, and practical fixes such as admission control, block-size tuning, and observability.

    1. A Counterintuitive Production Incident

    An inference team at a cloud provider was serving a very large mixture-of-experts (MoE) model online on a single node with 8 next-generation accelerator cards. To reduce response time for long-context requests, they placed a shared cache in front of the runtime to store previously computed attention key/value intermediates, expecting requests with similar prefixes to hit the cache and skip redundant computation.

    The post-launch numbers were surprising: median latency barely moved, while tail latency for the slowest 1% of requests jumped from about 3.96 seconds to 17.3 seconds. The team’s first instinct was a full rollback. The retrospective came down to one sentence: reading from a cache is not free, and that cost has been severely underestimated.

    2. Understanding the Workload and Memory Layout

    To understand the problem, you first need to understand how the model consumes memory bandwidth. The service uses a low-rank compression attention mechanism (a common KV compression approach in the industry) that compresses each token’s key/value information into a shared low-dimensional vector. As a result, the per-token cache footprint is fixed and small regardless of how many attention heads there are. At FP8 precision, every 256 tokens are packed into one block, and a block is roughly 12.4MB, or about 48.4KB per token.

    That number is deceptive: it looks small in isolation, but under long context and high concurrency, cache reads quickly go from “free reuse” to a major competitor for memory bandwidth.

    Illustrative capacity estimate:

    1. BLOCK_TOKENS = 256
    2. BYTES_PER_TOKEN = 48.4 * 1024 # FP8, ~48.4KB
    3. BLOCK_BYTES = BLOCK_TOKENS * BYTES_PER_TOKEN # ≈ 12.4MB
    4. def cache_read_bytes(prefix_tokens: int) -> int:
    5. blocks = (prefix_tokens + BLOCK_TOKENS - 1) // BLOCK_TOKENS
    6. return blocks * BLOCK_BYTES

    3. Why the Cache Made Things Slower: Four Mechanisms

    1. Bandwidth contention: Cache reads share the same memory bandwidth as the model’s forward pass. The compute savings from a hit are offset, or even outweighed, by the cost of moving 12.4MB-scale blocks.
    2. Addressing and matching cost: Prefix matching requires index structures and hash verification. Long prefixes and fragmented block layouts make addressing overhead grow nonlinearly.
    3. Tail latency amplification: The hit path introduces extra synchronization points and queuing. Once the hit rate fluctuates, slow requests cluster together, p99 rises sharply, and the median barely notices.
    4. Capacity and eviction thrashing: The cache takes up available memory, triggering more frequent swap-in and swap-out and creating a “the busier it gets, the slower it gets” feedback loop.

    4. Evaluation Framework: Calculate the Breakeven Point First

    Don’t enable caching on intuition. Calculate the breakeven point first. Let T_compute be the effective compute time of a single forward pass, T_read the time to read the cache, and h the hit rate. The expected gain is positive when approximately:

    1. h * T_compute > T_read + T_overhead

    In practice, use shadow traffic for A/B testing: keep the request distribution fixed, toggle only the cache on and off, and focus on three curves — p95/p99, bandwidth usage, and remaining memory headroom — rather than average latency alone.

    5. Rework Plan: Making the Cache Actually Faster

    • Block size tuning: Increase block size to amortize addressing overhead, but cap the amount moved per read to avoid bandwidth spikes.
    • Admission control: Enable the cache only for long-prefix, stable hotspot requests; send short requests straight down the compute path.
    • Asynchronous prefetch and tiered storage: Overlap cache reads with computation, push cold data down to higher-capacity tiers, and keep hot data close to the compute.
    • Observability: Build monitoring, alerting, and log dashboards for hit rate, bytes read, addressing time, and eviction counts to close the loop.

    Illustrative admission policy:

    1. def should_use_cache(req) -> bool:
    2. return req.prefix_tokens >= 4096 and req.is_stable_hotspot

    6. Conclusion

    A cache is not a free accelerator. For bandwidth-sensitive workloads like very large MoE models and low-rank compressed attention, you must account for read costs in a data-driven way, control admission, and tune block size — only then does a shared cache go back to reducing latency instead of amplifying tail latency.