Why Caching Slows Down Large Model Inference: A Systematic Analysis from Hit Rate to Tail Latency

    Caching is often seen as a natural optimization for large model inference, but real-world deployments can reveal the opposite: cache access paths that are slower than recomputation. This article examines a case where enabling a shared cache for attention states increased p99 latency from approximately 3.96 seconds to 17.3 seconds without improving median latency, and systematically analyzes why this happens. It covers what models actually cache, why cache reads can be more expensive than recomputation, how Mixture-of-Experts architectures amplify the problem, and provides concrete guidance on layered cache design, block size tuning, cost modeling for "read vs. compute" decisions, and production-ready optimization principles such as cache bypassing, budget limits, timeouts, and observability.

    In large model inference systems, “save computed results and reuse them next time” sounds like the most natural optimization—especially for long-context requests, where attention computation must process a large number of historical tokens. If intermediate results could be reused, repeated computation could theoretically be eliminated.

    But engineering practice is rarely that simple. Consider a large-scale Mixture-of-Experts (MoE) model running on a node equipped with multiple high-performance accelerators. To reduce the computational cost of long-context requests, the system introduced a shared cache layer to store intermediate attention states. The result: median latency showed virtually no improvement, while the slowest 1% of requests saw latency jump from approximately 3.96 seconds to 17.3 seconds. In other words, the cache failed to meaningfully optimize the majority of requests and significantly amplified tail latency.

    This case reveals a frequently overlooked fact: a cache is not a free “fast path.” Reading from a cache consumes compute cycles, VRAM bandwidth, interconnect bandwidth, thread resources, and scheduling time. When the cache access path is more expensive than recomputation, the system exhibits the counterintuitive phenomenon of “the cache being slower than the computation.”

    First, Understand What the Model Is Actually Caching

    To analyze cache overhead, we must first clarify what is being cached.

    In autoregressive large models, tokens are generated one at a time. Each time a new token is generated, the attention module needs to access the intermediate states for previous context—typically referred to as key-value (KV) cache. This avoids reprocessing the full history on every generation step, making it a critical optimization for long-context inference.

    For standard multi-head attention, each token requires storing multiple key-value pairs. The more attention heads, the larger the cache tends to be. Some newer attention architectures compress the shared information across heads into a lower-dimensional latent representation, then recover or map it to the required structure during computation. This can significantly reduce the cache footprint per token.

    In a typical configuration, the system may chunk tokens into fixed-size blocks and store data in low-precision formats. For example, with 256 tokens per cache block, a single block might be around 12.4 MB, averaging roughly 48.4 KB per token. This may seem small, but when a single request contains tens of thousands of tokens or more, the cache footprint can reach hundreds of megabytes. When the system serves many concurrent requests, total cache capacity and access traffic grow rapidly.

    Therefore, cache optimization cannot stop at “can we avoid computation?” It must answer:

    1. Where is the cached data stored?
    2. Can requests reliably hit the cache?
    3. How much data must be transferred per hit?
    4. How many memory and network hops does the data traverse?
    5. When multiple requests access the cache concurrently, does contention occur?
    6. Is the cache read time less than the recomputation time?

    Why Cache Reads Can Be Slower Than Recomputation

    1. Computation Has High Locality; Cache Reads May Span Multiple Layers

    Recomputation typically happens locally on the accelerator. Model weights, temporary tensors, and intermediate results participate in matrix operations directly through high-bandwidth VRAM. Modern accelerators excel at large-scale, contiguous, regular computation—especially batched matrix multiplication and vectorized operations.

    A shared cache, however, is often not located on the same accelerator handling the current request. The read path may look like this:

    1. Request process
    2. → Local cache index
    3. → Remote cache node
    4. → Inter-node interconnect
    5. → Remote VRAM or host memory
    6. → Fragmented data reads
    7. → Return to executing accelerator
    8. → Data format conversion and layout rearrangement

    Any one of these steps can become a bottleneck. Even if the cached data exists, the compute unit may not be able to use it immediately.

    Worse, recomputation is typically a continuous, large-batch operation, while cache reads often manifest as many small, scattered accesses. The former fully utilizes hardware throughput; the latter is vulnerable to access count, synchronization waits, and address translation overhead.

    2. Cache Hit Rate Does Not Equal Effective Gain

    Many systems only report the cache hit rate without calculating actual cache benefit.

    For example, a system reporting a 70% hit rate may look excellent. But if the hit requests only reuse a short segment of context, and every hit requires index lookup, permission checks, block location, data transfer, and format conversion, the net gain may still be negative.

    A more accurate metric is “effective time saved”:

    1. Effective gain =
    2. Avoided computation time
    3. - Cache lookup time
    4. - Cache read time
    5. - Data transfer time
    6. - Format conversion time
    7. - Synchronization and scheduling time

    Only when the effective gain is positive does the cache truly provide optimization value.

    It is recommended to track the following metrics:

    • Request-level hit rate
    • Length of hit data
    • Bytes read per access
    • Cache query latency
    • Data transfer latency
    • Decompression or dequantization latency
    • Actual compute latency for hit vs. miss requests
    • Queueing time caused by cache contention
    • p50, p95, p99, and higher percentile latencies

    3. Tail Latency Is Amplified by Shared Resources

    Caching hurts tail latency far more than average latency.

    Assume most requests read only a small amount of cached data, while a few requests need to read hundreds of cache blocks. When multiple long requests arrive simultaneously, they compete for limited VRAM bandwidth, interconnect bandwidth, and cache server threads. Short requests may complete quickly, but long requests queue up—resulting in noticeable p99 latency inflation.

    Shared caches can also produce a “thundering herd” effect: when a hot prefix is accessed by many requests at the same time, the cache server receives a burst of read tasks. Even if the data is already cached, the system must create access descriptors, resolve addresses, and initiate transfers for each request. The more concentrated the cache hits, the greater the instantaneous pressure.

    This demonstrates that cache evaluation cannot rely on average throughput alone. For online inference services, tail requests must be the priority, because user experience and service-level objectives are typically determined by the slowest requests.

    Why Mixture-of-Experts Models Add Complexity

    Mixture-of-Experts (MoE) models activate only a subset of experts per input token. Their advantage: the total model parameter count can be very large, while each token only activates a fraction of the experts.

    However, this sparse computation structure increases scheduling complexity. Different requests may be routed to different experts, and expert placement across devices may vary. When cached content does not align with the execution location of the current request, the system must transfer data across devices or even reorganize it.

    For example:

    1. Cache hit
    2. → Historical state on device A
    3. → Current request scheduled to device C
    4. → Cross-device transfer required
    5. → Data rearranged on device C
    6. → Proceed with attention computation

    If cross-device transfer costs are high, the computation saved by the cache may be immediately offset by communication overhead. In scenarios with frequent expert routing changes, the distance between cache location and compute location must be considered in the design—not treating the cache as an isolated module.

    Proper Cache Design Should Be Layered

    A more robust approach is usually not “put everything into a shared cache,” but rather building a hierarchical cache.

    Layer 1: Local Accelerator Cache

    The local cache is closest to the compute unit, offering low latency and high bandwidth—ideal for data that will be used imminently. Its downside is limited capacity and pressure on VRAM.

    Layer 2: Intra-Node Shared Cache

    When multiple accelerators are connected via high-speed interconnect, some data can be shared within the node. This layer has higher access cost than local cache but is typically cheaper than cross-node access. It suits context blocks with relatively high reuse probability.

    Layer 3: Remote Cache

    Remote cache offers larger capacity but requires network or inter-node interconnect. It is only worthwhile when cache blocks are sufficiently large, the reuse probability is sufficiently high, or the recomputation cost is significantly greater.

    Layer 4: Persistent Storage

    Persistent storage suits session-level data, offline task data, or data that needs to be reused across instances. It should not serve as a low-latency data source for per-step online inference.

    The cache policy can be abstracted as:

    1. if local hit:
    2. reuse directly
    3. elif intra-node hit and estimated transfer cost < recompute cost:
    4. read intra-node cache
    5. elif remote hit and reuse length is sufficiently large:
    6. batch read remote cache
    7. else:
    8. skip cache and compute directly

    The key is not “read on hit,” but “judge whether it is worth reading before reading.”

    Cache Block Size Must Match Access Patterns

    Cache blocks that are too small result in excessive metadata, higher access counts, and frequent request scheduling. Blocks that are too large may cause wasted data transfer.

    For example, if a request only needs to reuse a few dozen tokens but the system must read a block containing hundreds of tokens, significant bandwidth is wasted on content that will never be used. Conversely, if blocks are too small, the system may issue many small requests to read contiguous context—ultimately slowed down by scheduling and synchronization overhead.

    Block size should therefore be determined by:

    • Typical context length of requests
    • Contiguity of prefix reuse
    • Accelerator VRAM bandwidth
    • Inter-node interconnect bandwidth
    • Cache server concurrency capability
    • Data decompression and format conversion cost
    • Online service tail latency requirements

    In practice, offline playback tests should be run with different block sizes, measuring hit rate, bytes read, effective reuse ratio, and end-to-end latency—rather than only comparing single cache read speeds.

    Use a Cost Model to Decide “Read or Compute”

    Cache decisions should be based on a simple, interpretable cost model.

    Let:

    • (T_c) represent recomputation time
    • (T_l) represent cache lookup time
    • (T_m) represent data movement time
    • (T_r) represent data rearrangement or format conversion time
    • (T_s) represent synchronization and queueing time

    Then the total cache path cost is:

    1. T_cache = T_l + T_m + T_r + T_s

    Only when:

    1. T_cache < T_c

    does reading the cache provide theoretical benefit.

    We can further incorporate hit probability (P_{hit}):

    1. Expected time =
    2. P_hit × T_cache
    3. + (1 - P_hit) × (T_l + T_c)

    Since a lookup cost is typically incurred even on a miss, a low-hit-rate cache could be slower than no cache at all. This formula also indicates that cache systems need a “minimum reuse threshold”—for example, only initiate remote reads when the predicted reusable prefix is sufficiently long.

    How to Diagnose Cache-Induced Performance Regression

    When investigating such issues, don’t only look at model computation time. Perform end-to-end decomposition.

    Build a timeline like this:

    1. Request arrival
    2. → Cache key generation
    3. → Index lookup
    4. → Hit confirmation
    5. → Data read
    6. → Data transfer
    7. → Data conversion
    8. → Attention computation
    9. → Expert routing
    10. → Output generation

    Record start time, end time, and data volume for each stage. Simultaneously correlate device utilization, VRAM bandwidth, interconnect bandwidth, cache queue length, and concurrent request count.

    Watch for these phenomena:

    1. Compute utilization drops while interconnect bandwidth approaches saturation
    2. Cache hit rate rises, but effective reuse length does not increase
    3. Average latency barely changes while p99 rises noticeably
    4. Cache read request count is far higher than the actual number of hit blocks
    5. Miss requests still bear a high index lookup cost
    6. Long requests arriving together cause visible queueing in the cache

    If these appear simultaneously, the bottleneck is usually not model computation—it is the cache access path and shared resource contention.

    Optimization Principles for Production Environments

    First, the cache must be bypassable. The system should be able to disable remote reads at any time based on real-time load, preventing cache failures or congestion from disrupting the primary path.

    Second, the cache must have budget limits. Limit the maximum bytes read per request, maximum cache block count, and maximum wait time.

    Third, the cache must support timeouts. If data does not return within the benefit threshold, the system should fall back to recomputation rather than wait indefinitely.

    Fourth, the cache must differentiate request types. Short requests, low-reuse requests, and high-concurrency bursts should not use the same policy as long-context, high-reuse requests.

    Fifth, cache policy must be observable. Hit rate is only the starting point. Track effective hit rate, cost per unit of reuse, cache benefit distribution, and tail latency changes.

    Sixth, optimization must be validated with real traffic. Offline benchmarks often fail to reflect request length distribution, concurrency variation, and hot-prefix contention. Production environments should use canary releases and gradual traffic ramping.

    Conclusion

    The essence of caching is not “saving data”—it is trading additional storage, transfer, and management costs for reduced duplicate work. For large model inference, recomputation is not always the most expensive part. When computation is highly parallel and data resides locally, remote cache reads can become the actual bottleneck.

    Therefore, judging whether a cache is effective cannot stop at “did we hit?” A comprehensive evaluation must include compute cost, access path, data volume, device locality, concurrency contention, and tail latency. A mature cache system should have layered storage, dynamic bypass, cost estimation, timeout fallback, and complete monitoring capabilities.

    When cache access cost exceeds recomputation cost, deliberately skipping the cache is not a failure—it is a more rational performance decision.