Why Caching Can Slow Down LLM Inference: From Cache Hit Rate to Tail-Latency Optimization

    Caching can reduce repeated computation in large language model inference, but a cache hit is not automatically a performance gain. This article explains how remote memory access, cross-device transfers, synchronization, MoE routing, compressed attention states, and resource contention can increase p99 latency. It also presents cost-aware cache policies, tiered storage, overlapping data movement with computation, safeguards, and an experiment framework for evaluating end-to-end benefits.

    1. Caching Does Not Automatically Mean Faster Inference

    In large language model inference systems, caches are typically used to store previously computed intermediate results. When processing long contexts, for example, a model generates attention-related key-value data for historical tokens. If a later request contains the same or a highly similar prefix, the system may reuse those results and avoid repeating the computation.

    The idea appears straightforward:

    1. A request arrives.
    2. The system generates a cache key from the context.
    3. It queries a shared cache.
    4. If the data is found, it reads the stored intermediate results.
    5. It computes only the newly added portion.

    If reading from the cache were nearly free, a cache hit would naturally reduce computation time. However, at very large model scales, cached data is often not stored in the high-speed memory of the current compute unit. It may reside in the memory of another GPU, in host memory, or even on a more distant storage device.

    In that case, “reusing data” is no longer a simple lookup. It may involve address resolution, metadata queries, cross-device transfers, memory copies, synchronization, and task rescheduling.

    The real comparison is therefore not whether computation is expensive, but this:

    Is recomputing a segment more expensive than locating, transferring, validating, and integrating the cached data?

    If the answer is no, more aggressive caching can make the system slower.

    2. Why the Problem Appears First in p99 Latency

    After a cache is deployed, median latency may change very little while the slowest requests become significantly slower. This is not contradictory. Cache operations introduce more uncertainty into the request path.

    For a standard request, the model’s computation path is relatively stable. Even when input lengths vary, computation can generally be scheduled through established batching mechanisms. Cache reads introduce additional variables:

    • Which device stores the cached data;
    • Whether the target device is currently busy;
    • Whether cross-device or cross-node transfer is required;
    • How many requests are competing for bandwidth;
    • Whether cache blocks are contiguous;
    • Whether multiple shards must arrive together;
    • Whether the compute stream must wait for synchronization after the read completes.

    Many requests may hit a local cache, or the system may have sufficient capacity when the read occurs. Their latency therefore changes little. A smaller number of requests may encounter remote data, a congested link, memory fragmentation, or a scheduling conflict, producing a long tail.

    A request’s total time can be roughly represented as:

    1. Total latency =
    2. Queueing time
    3. + Cache lookup time
    4. + Cache transfer time
    5. + Data loading and synchronization time
    6. + Computation time for cache misses
    7. + Output generation time

    Cache transfer and synchronization typically have a wide range of possible durations. Their average may be low, but a small number of severely blocked requests can quickly worsen p99 and p999 latency.

    This reflects a broader performance principle: average latency is useful for measuring overall efficiency, while tail latency better reveals how the system behaves under resource contention and exceptional paths.

    3. Why Mixture-of-Experts Models Make Caching More Complex

    Mixture-of-Experts (MoE) models select only a subset of experts for each input. This allows the model to increase its total capacity while limiting the amount of computation required for each token.

    However, this architecture also creates more complex access patterns:

    1. Different tokens may be routed to different experts.
    2. Expert computation may be distributed across devices.
    3. Some experts may become hotspots.
    4. Routing results may differ across requests.
    5. Data transfer and computation may occur at the same time.

    In this environment, the location of cached data matters. If the cache is stored away from the device responsible for the current computation, the system must move the data before it can be used.

    For a cache block of size (S) and an effective bandwidth of (B), the transfer time alone is approximately:

    1. T_transfer ≈ S / B

    Actual latency also includes request initiation, queueing, memory allocation, DMA scheduling, and synchronization overhead:

    1. T_cache =
    2. T_lookup
    3. + T_queue
    4. + T_transfer
    5. + T_copy
    6. + T_sync

    When cache blocks are small, fixed overhead accounts for a larger share of total latency. When blocks are large, each transfer may consume substantial bandwidth. There is no universally optimal block size; it must be evaluated against context length, concurrency, link bandwidth, and computation granularity.

    4. Low-Rank Attention Structures Reduce Capacity Requirements, Not Access Costs

    Modern models often use low-rank or compressed representations to store intermediate attention results. Compared with traditional multi-head attention, these designs can significantly reduce the amount of data stored per token, making long-context inference more practical.

    In some implementations, data is grouped into fixed-size token blocks and stored in a low-precision format. This reduces memory consumption and can improve transfer efficiency.

    But smaller data does not mean free data access.

    As the size of each cached item decreases, systems may choose to retain more historical context and expand cache reuse. This can lead to:

    • A larger cache directory;
    • More frequent lookups;
    • More cross-device accesses;
    • Greater competition between read requests and compute tasks for bandwidth;
    • More frequent loading steps after cache hits.

    Compressed data may also need to be unpacked, converted, or rearranged at the destination. If a compute kernel requires a specific memory layout and the cached data uses a different layout, the system must perform a reformatting step after the read. The computation saved by caching can then be offset by data preparation.

    Cache evaluation should therefore measure the complete post-hit path, not just cache capacity and hit rate.

    5. The Most Common Mistake: Measuring Hit Rate Without Measuring Net Benefit

    Cache hit rate is an important metric, but it is not proof that caching is effective.

    Suppose one system achieves an 80% hit rate, but most hits require expensive cross-device reads. Another system has only a 50% hit rate, but most hits come from local high-speed storage. The second system may still deliver lower overall latency.

    A more useful metric framework should include at least the following categories.

    1. Lookup Metrics

    • Number of lookups;
    • Hit rate;
    • Miss rate;
    • Average lookup latency;
    • Lookup p95 and p99 latency;
    • Metadata service load.

    2. Data-Path Metrics

    • Local read ratio;
    • Cross-device read ratio;
    • Cross-node read ratio;
    • Actual bytes transferred;
    • Effective bandwidth;
    • Number of data copies;
    • Synchronization wait time.

    3. End-to-End Metrics

    • Time to first token;
    • Total latency per request;
    • p50, p95, p99, and p999 latency;
    • Requests completed per second;
    • Tokens generated per second;
    • Compute-unit utilization;
    • Memory and interconnect utilization.

    4. Economic Metrics

    • Compute resources consumed per request;
    • Actual savings from each cache hit;
    • Cache maintenance cost;
    • Additional bandwidth consumed by caching;
    • Per-request cost before and after enabling the cache.

    The key metric is net benefit:

    1. Net benefit =
    2. Saved computation time
    3. - Cache lookup overhead
    4. - Data transfer overhead
    5. - Synchronization overhead
    6. - Additional resource contention cost

    Caching is worth keeping only when the net benefit is positive.

    6. Directions for Improving the Cache System

    1. Build a Tiered Cache Instead of Putting Everything in a Shared Layer

    A multi-level cache can be organized according to access distance:

    • Level 1: High-speed memory on the current compute device;
    • Level 2: Memory on other devices within the same node;
    • Level 3: Host memory or node-level shared memory;
    • Level 4: Remote persistent storage.

    The closer a tier is to the compute unit, the faster it is, but the smaller its capacity tends to be. The system should prioritize local hits and access remote tiers only when the expected benefit is high enough.

    If a remote read is expected to take 10 milliseconds while recomputation takes only 6 milliseconds, the system should not initiate the remote access merely to achieve a formal cache hit.

    2. Introduce Cache Admission Policies

    Not every request should be written to the cache. Admission decisions can consider:

    • Whether the context is sufficiently long;
    • Whether the prefix is likely to recur;
    • The probability of future reuse;
    • Whether the write cost is lower than the computation it may save later;
    • Whether the entry will consume space needed by hot requests.

    Writing a one-time long context to the cache usually has little value. The cache should prioritize data with high reuse probability and high computational value rather than maximizing capacity indiscriminately.

    3. Use Cost Awareness for Different Cache Blocks

    Cache blocks can carry metadata such as:

    1. {
    2. access_count,
    3. last_access_time,
    4. data_size,
    5. storage_level,
    6. compute_saving_estimate,
    7. transfer_cost_estimate
    8. }

    Eviction should not rely exclusively on least recently used (LRU) policies. It can also consider a priority score such as:

    1. cache_priority =
    2. Reuse frequency
    3. × Computation saved per access
    4. ÷ Read cost

    Cost-aware policies are better suited to heterogeneous storage and cross-device environments.

    4. Overlap Cache Reads with Computation

    If computation cannot begin until the cache read has fully completed, transfer time is directly exposed to the user. A better approach is to pipeline the work:

    1. Prefetch the next batch of cache blocks.
    2. Compute the current batch.
    3. Pass data to the next computation as soon as it arrives.
    4. Recompute cache misses in parallel.

    In the ideal case, transfer time is hidden behind computation:

    1. Total time ≈ max(computation time, data transfer time)

    rather than being added directly to it:

    1. Total time = computation time + data transfer time

    Overlapping execution must still prevent excessive bandwidth contention. Otherwise, prefetching can slow down the computation currently in progress.

    5. Set Budgets and Circuit Breakers for Cache Requests

    The cache layer should not serve unlimited read traffic. It should define controls such as:

    • Maximum read volume per request;
    • Maximum concurrent reads per device;
    • Per-node bandwidth budgets;
    • Timeout thresholds;
    • Conditions for disabling remote reads;
    • Degradation strategies under high load.

    If cache-related queueing continues to increase, the system can temporarily disable remote caching, retain only local caching, or fall back to recomputation. Performance optimization must allow the system to skip the cache; otherwise, the cache layer can become a bottleneck instead of an auxiliary component.

    7. How to Design Reliable Experiments

    Performance experiments should not compare only two aggregate results—caching enabled and caching disabled. The request path should be decomposed into its individual stages.

    At minimum, compare the following configurations:

    1. All data served from local cache;
    2. All data served from remote cache;
    3. Only highly reusable prefixes cached;
    4. Random caching;
    5. Read-only caching with no writes;
    6. Short-lived cache writes only;
    7. High-concurrency and low-concurrency workloads;
    8. Different context lengths;
    9. Different cache hit rates;
    10. Different cache block sizes.

    Each experiment should record the complete latency distribution rather than only the average. In particular, evaluate:

    • Whether p50 improves;
    • Whether p95 becomes worse;
    • Whether p99 develops spikes;
    • Whether cache hits actually reduce computation;
    • Whether compute-unit utilization decreases;
    • Whether interconnect bandwidth becomes a bottleneck;
    • Whether memory allocation or synchronization jitter appears.

    Fault injection is also important. For example, reduce link bandwidth, increase queueing in the cache service, or make selected nodes unavailable. Then observe whether the system degrades smoothly.

    8. Engineering Conclusions

    Caching is a resource-exchange mechanism. It uses additional storage capacity and data-access overhead to reduce computation. This trade-off works only when access costs are lower than recomputation costs.

    In large model inference, cache value depends on at least the following factors:

    • Whether the data is genuinely duplicated;
    • Whether the cache is stored in an appropriate location;
    • Whether cross-device access is required;
    • Whether transfers compete with computation for resources;
    • Whether the data layout requires conversion;
    • Whether concurrent requests create queueing;
    • Whether cached data can be used directly by the compute kernel;
    • Whether the system can fall back quickly when remote reads fail.

    Cache optimization should therefore not target the highest possible hit rate. Its goal should be a net improvement in end-to-end latency and system throughput.

    A more reliable implementation path is:

    1. Establish a no-cache baseline.
    2. Measure the cost of recomputation.
    3. Measure access costs at each storage tier.
    4. Enable caching only for high-value data.
    5. Add local-first policies and remote-read circuit breakers.
    6. Hide transfer time through pipelining.
    7. Continuously monitor tail latency.
    8. Adjust policies dynamically according to real traffic.

    Caching becomes genuinely valuable when it changes from a feature that is enabled by default into a scheduling decision based on explicit cost evaluation. Many systems fail not because the caching concept is wrong, but because they mistake cache hits for performance gains and overlook the real costs of data movement, resource contention, and tail latency.