LLM Inference Caching: Why Cache Reads Can Be Slower Than Recomputing

    This article examines why caching in large language model inference is not free, how shared cache reads can increase tail latency even when median latency looks stable, and how teams can evaluate cache net benefit, design tiered caching, and monitor the full cache access path.

    Caching is often seen as an important way to reduce computation overhead in large language model (LLM) inference systems. This is especially true for long-context workloads: the system can save attention intermediate states that have already been processed, and when a later request contains the same or a similar prefix, it can read those states directly and theoretically skip repeated computation.

    But a cache is not a free add-on. It consumes storage space and requires lookup, metadata management, data movement, format conversion, network communication, and device-memory copies. When the cache is located outside the compute device, or when the cache hit rate is not high enough to cover these extra costs, the system can produce a counterintuitive result: reading from cache is slower than recomputing.

    A very large Mixture-of-Experts (MoE) inference service encountered this kind of problem. The system ran on nodes composed of multiple high-performance accelerators. To improve long-context request processing, the engineering team added a shared cache to store previously computed attention-related intermediate states. After the feature was enabled, median latency barely changed, but the slowest 1% of requests rose from about 4 seconds to more than 17 seconds, and the feature eventually had to be temporarily disabled.

    This case shows that cache evaluation cannot rely only on average latency, nor can it simply compare “computation volume” with “cache data volume.” What really determines the benefit is the full-path cost of one cache read and its impact on concurrent scheduling and tail requests.

    1. Why LLM Inference Needs Caching

    Autoregressive models usually generate content token by token. For input that has already been processed, the attention module produces a set of intermediate states that later steps still need. If the system reprocessed all historical content every time it generated a new token, computation would grow rapidly with context length.

    Therefore, inference engines usually store the keys and values corresponding to historical tokens, or store compressed equivalent representations. In the subsequent generation phase, only the new token needs to be processed while historical states are read. For long-text requests, this kind of cache can significantly reduce repeated computation.

    In models that use low-rank compressed attention mechanisms, historical states are further compressed. Regardless of changes in the number of attention heads, the amount of data that must be stored per token can remain within a relatively stable range. In a typical configuration, the system may organize data into blocks based on a fixed number of tokens and store them in a low-precision format. Although a single data block is much smaller than a full-precision representation, under long contexts and high concurrency the cumulative capacity can still be substantial.

    This kind of cache can be divided into two types:

    1. Local cache: located in the current accelerator memory or host memory. It has a short access distance and lower latency, but limited capacity.
    2. Shared cache: located on other devices, remote memory, or a dedicated storage system. It offers larger capacity and can be reused across requests, but requires additional data transfer and scheduling paths.

    Problems often appear in the second type. Although it offers higher capacity, it can turn an apparently simple “read” into a complex system operation.

    2. The Real Cost of a Cache Read

    Cache access includes at least the following steps:

    • Compute an index based on the request prefix;
    • Look up cache metadata;
    • Determine whether the data is complete and whether the version matches;
    • Select a storage location;
    • Allocate a target buffer;
    • Move data from a remote location or another device;
    • Decompress, decode, or convert the format;
    • Place the data into an area directly accessible by the compute device;
    • Synchronize with the current inference task.

    Queuing at any one of these stages can amplify overall latency.

    Many teams estimate cache benefit by comparing only two quantities: how much compute recomputation requires, and how many bytes a cache read must transfer. This estimate is too simplistic, because the actual transfer is not an isolated action. It also competes for device memory bandwidth, interconnect links, DMA channels, memory pools, and scheduling threads.

    For example, suppose a request reads a large amount of historical state. Even if the cache system itself has high average throughput, an individual request may be delayed for reasons such as:

    • Many concurrent requests read at the same time, causing link congestion;
    • Data is split into many small blocks, requiring frequent task submissions;
    • Target device memory is insufficient, triggering memory compaction or waiting for reclamation;
    • Compute tasks and data-transfer tasks contend for the same hardware resources;
    • Cache data is distributed across multiple locations, requiring multiple accesses;
    • An abnormal transfer of one data block causes the entire request path to wait.

    Therefore, cache cost cannot be expressed only as “bytes read divided by bandwidth.” A more reasonable model should include fixed overhead, queuing overhead, and synchronization overhead:

    Total cache cost = lookup cost + scheduling cost + transfer cost + conversion cost + waiting cost

    Only when the computation time saved is greater than this total cost does the cache create real value.

    3. Why Median Latency Stayed Flat While p99 Rose Sharply

    After a cache is introduced, median latency changing little while tail latency deteriorates significantly is a very typical phenomenon in distributed inference systems.

    The median reflects only the performance of half the requests. For requests with high hit rates, small cache data, and low system load, the cache may indeed save computation time. But a small number of complex requests may trigger remote reads, data reorganization, or resource contention, resulting in extremely high latency. These requests do not significantly change the median, but they directly push up p99 and higher percentiles.

    Tail latency is usually determined by the slowest stage, not the average stage. A request may need to read a dozen or more data blocks, and if only one block experiences severe queuing, the entire request must wait. As the number of data blocks increases, the probability of encountering a slow block also increases.

    In addition, a shared cache can create cascading effects:

    1. Some requests take longer to read from cache;
    2. Tasks on accelerators occupy resources for longer;
    3. Subsequent requests queue up;
    4. Buffers cannot be released in time;
    5. Memory pressure rises, triggering more compaction and waiting;
    6. Overall tail latency continues to worsen.

    This is why observing only average latency can easily lead to the wrong conclusion. An inference service should monitor at least p50, p90, p95, p99, and higher percentiles at the same time, and report cache-hit requests, cache-miss requests, and partial-hit requests separately.

    4. Cache Hit Rate Does Not Equal Cache Benefit

    “High hit rate” is a common performance metric for cache systems, but it cannot by itself prove that the cache is effective.

    First, hit rate only means that data was found; it does not mean the read cost is low. If the hit data is located remotely and requires transferring hundreds of megabytes or more, the hit itself can become a burden.

    Second, different hits have different value. Reusing a very short prefix saves limited computation; reusing a very long prefix has higher theoretical benefit but also requires reading more cache data. The two cases cannot be judged only with a binary “hit” versus “miss” distinction.

    Third, partial hits may be the hardest case to handle. The system reads part of the data, finds that the remaining part is unavailable, and ultimately still has to recompute. In this case, computation is not fully saved, and ineffective transfer is added.

    More reasonable metrics include:

    • Hit rate;
    • Effective hit rate;
    • Computation time saved per hit;
    • Transfer time generated per hit;
    • Net cache benefit;
    • Queuing time caused by caching;
    • Benefit curves under different data sizes.

    The net benefit of one cache operation can be defined as:

    Net benefit = skipped computation time - total cache access time

    A request should be allowed to use the shared cache only when the net benefit is positive and does not significantly worsen the waiting time of other requests.

    5. Practical Optimization Strategies

    1. Build Local, Nearby, and Remote Tiered Caches

    Do not place all cache data in the same shared storage layer. A tiered structure can be built according to access distance:

    • Tier 1: current accelerator memory;
    • Tier 2: other high-speed memory within the same node;
    • Tier 3: nearby nodes or dedicated cache devices;
    • Tier 4: larger, lower-speed storage.

    High-frequency, small, low-latency content should be placed locally first; low-frequency, large content should be pushed down to remote tiers. On access, the system should try nearer tiers first and access farther tiers only when the expected benefit is high enough.

    2. Decide by Benefit, Not by Hit

    Before reading, the system can estimate:

    • How much computation can be skipped;
    • How much data must be read;
    • The current level of link congestion;
    • Whether the target device has enough space;
    • The priority and deadline of the current request.

    If the estimated cache read cost is higher than recomputation, the system should compute directly and not access the remote cache. This dynamic choice between “compute” and “read” is more robust than always enabling caching.

    3. Avoid Many Small-Block Accesses

    Over-splitting cache data creates more indexing, scheduling, and synchronization overhead. Adjacent data blocks can be merged within a reasonable range to reduce the number of accesses. At the same time, block size should not be expanded blindly, because that can increase ineffective reads. Block size should be determined through stress testing based on context length, concurrency, and network characteristics.

    4. Pipeline Transfer and Computation

    If the hardware and execution engine support it, the next batch of cache data can be prefetched while the current computation is running, forming a “compute-transfer” pipeline. However, pipelining does not mean there is no cost. Prefetch depth still needs to be controlled to avoid excessive prefetching saturating device memory or links.

    5. Set Timeouts and Circuit Breakers for Caches

    When shared cache latency continues to rise, the system should automatically reduce its usage ratio or even temporarily disable remote reads. The cache should not become a single point of dependency for inference services. The system can set:

    • Per-read timeout;
    • Consecutive failure threshold;
    • p99 latency trigger threshold;
    • Node-level rate limiting;
    • Dynamic degradation by request type.

    After degradation, local recomputation provides a fallback, which is usually more reliable than making all requests wait indefinitely.

    6. Monitoring Must Cover the Full Path

    It is recommended to split cache-related metrics into four categories.

    Request-layer metrics: overall latency, generation speed, latency at different percentiles, timeout rate, and error rate.

    Cache-layer metrics: hit rate, partial hit rate, bytes read, average block size, cache eviction rate, and data validity period.

    Resource-layer metrics: device memory usage, memory bandwidth, interconnect utilization, DMA queue length, and thread pool queue time.

    Decision-layer metrics: actual time saved after a cache hit, cache read duration, recomputation duration, and net benefit per cache operation.

    In particular, full request tracing should be recorded, with separate timing for lookup, queuing, transfer, conversion, synchronization, and computation. Only in this way can teams determine whether the problem comes from cache storage, the network link, or inference scheduling.

    7. Conclusion: More Cache Is Not Always Better

    The core of cache optimization is not storing more data, but using the cache for the right request, at the right time, and in the right location.

    For LLM inference, computation, storage, and transfer already form a tightly coupled whole. A cache read may save a large amount of matrix computation, but it may also slow down the entire system through bandwidth contention, task queuing, and synchronization waits. Especially in high-concurrency services, average performance improvement does not necessarily mean a better user experience; tail latency is an important basis for judging whether the system is stable.

    Therefore, before designing a shared cache, teams should build a complete cost model and validate the following questions with real workloads: Does a cache hit really save time? Does reading compete with compute resources? Do partial hits cause extra waste? Does peak load amplify tail latency? If these questions do not have clear answers, blindly expanding cache capacity may simply move the compute bottleneck to storage and communication.

    A mature solution should allow the system to dynamically choose between “reading from cache” and “computing directly,” and use tiered caching, pipelined transfer, rate limiting, circuit breaking, and fine-grained monitoring to make caching a controllable optimization rather than a new performance risk.