When Cache Reads Are Slower Than Recomputation: Hidden Costs in LLM Inference
KV cache reuse is widely assumed to speed up LLM inference, but this case study shows that cache reads carry their own costs—data transfer, deserialization, queuing, and synchronization—that can be amplified on tail requests. This article breaks down why median latency hides the problem, how to decompose read costs, how to locate bottlenecks with percentile analysis and per-stage instrumentation, and how to restructure caching so every read is actually worth it.
1. Why Caching Carries High Expectations
The dominant cost in LLM inference comes from long contexts. Every time the model generates a new token, it must access the intermediate representations of all previous tokens. If multiple requests share a similar prefix—such as the same system prompt or the same long document—the intermediate results for that prefix can be saved and reused by later requests, avoiding redundant forward computation.
This approach rests on one premise: reading the saved results takes far less time than recomputing them. That premise is rarely validated on its own. Most teams assume “reuse is always faster,” so they focus on hit rates and ignore the latency distribution of the reads themselves. That is the core lesson of this case: a cache read is itself a costly operation, and that cost can be amplified on tail requests.
2. The Data Scale of Attention Intermediate Results
To understand the cost of cache reads, you first need to know what is stored. In mainstream attention computation, each token produces a set of key and value vectors, which are kept throughout inference as the key-value (KV) cache. As context grows, the KV cache’s memory footprint and bandwidth consumption grow linearly.
Some models adopt low-rank compressed attention designs that compress each token’s key-value information into a shared low-dimensional representation. The benefit is that the data stored per token is essentially independent of the number of attention heads, so the per-token data volume is fixed and small.
In this case, the numerical precision was FP8, with every 256 tokens packed into one block. A single block was about 12.4 MB, averaging roughly 48.4 KB per token. These numbers reveal two things. First, the data per token is indeed small. Second, a single hit usually requires reading multiple blocks. A prefix of several thousand tokens may correspond to a dozen or more blocks, adding up to hundreds of megabytes. Small data does not mean cheap reads.
The latency of one cache read can be broken down as follows:
read latency ≈ index lookup + data transfer + deserialization and copying + queue waiting + synchronization waiting
Data transfer time depends on effective bandwidth. When multiple requests and compute units share the link, effective bandwidth is far below the device’s rated peak, so actual transfer time is often much longer than a peak-based estimate would suggest.
3. Why Average Metrics Hide the Problem
The median reflects the experience of a typical request. The p99 reflects the experience of the slowest one percent. In this case, the median barely changed, meaning most requests did benefit from the cache or were barely affected by it. The problem was concentrated in the tail—and the tail is exactly what users notice most.
Tail slowdowns usually come from a few categories of causes:
- The barrel effect of batching: Inference systems often merge multiple requests into a batch computed together. The batch’s completion time is determined by its slowest request. If one request’s cache read stalls, the entire batch is dragged down.
- Resource contention: Cache reads share bandwidth, memory, and scheduling queues with normal computation. During read peaks, compute tasks queue up, and read tasks queue up too.
- Long-tail prefixes: A small number of requests hit a large number of blocks, and their read times far exceed the average. The average is diluted by the many short requests, hiding the cost of these long-tail ones.
Therefore, whether a cache is effective should be judged by percentile distributions, not by means or medians alone.
4. Decomposing the Cost of a Cache Read
Breaking the read process apart reveals the real cost of each stage.
1. Index lookup. The cache must determine whether the prefix is a hit. If the index structure requires locking under high concurrency, or the key computation itself is heavy, lookup becomes a bottleneck.
2. Data movement. Cached data may live in GPU memory, host memory, local disk, or remote nodes. The farther away it is, the slower the movement, and the more it is affected by network jitter.
3. Format conversion and copying. If the stored data’s memory layout differs from what computation requires, extra rearrangement and copying are needed. This cost is easily overlooked because it shows up in neither network nor storage metrics.
4. Queuing and contention. Once a read request enters a shared queue, it may wait for other reads or computations to finish. The longer the queue, the more pronounced the tail latency.
5. Synchronization waiting. In multi-GPU or multi-node setups, every device must receive the blocks it needs before proceeding. If any device’s read slows down, all other devices idle.
6. Fallback cost on misses. If a read times out or fails, the system either retries or recomputes. Retrying adds read time; recomputation adds compute time. Both make the request slower than if the cache had never been used.
The value of this decomposition is that it turns the vague judgment “the cache is slow” into concrete, individually testable questions.
5. How to Locate the Problem
Follow these steps to locate the problem instead of changing things based on intuition.
Step 1: Compare percentile distributions with the cache on and off. Using the same request traffic, run with the cache enabled and disabled, and record p50, p95, and p99. If only p99 degrades, the problem likely lies in tail mechanisms rather than in the cache’s basic design.
Step 2: Instrument each stage. Use code like the following to accumulate time spent in lookup, transfer, compute, and other stages:
import timefrom contextlib import contextmanagerstage_totals = {}@contextmanagerdef stage(name):start = time.perf_counter()try:yieldfinally:elapsed = time.perf_counter() - startstage_totals[name] = stage_totals.get(name, 0.0) + elapsed# Usagewith stage("cache_lookup"):hit = cache.lookup(prefix_key)with stage("cache_read"):blocks = cache.read_blocks(hit)with stage("compute"):output = model.forward(blocks, new_tokens)
Step 3: Group by request characteristics. Group requests by prefix length, number of hit blocks, and number of concurrent in-flight requests, and observe where tail latency concentrates. Long prefixes and high concurrency are usually the scenarios that expose problems first.
Step 4: Examine the timeline of tail requests. Trace requests above p99 and find which stage they spend the longest in. If the answer is “queuing,” the problem is scheduling; if it is “data movement,” the problem is data placement or bandwidth.
6. Turning the Cache into a Component That Actually Speeds Things Up
Once the problem is located, the goal of the rework is to make every read worthwhile. Common approaches include the following.
1. Set a Benefit Threshold
Read from the cache only when the expected benefit is positive. The benefit can be approximated as:
benefit = recomputation time - read time
When the benefit is negative, or small with large tail risk, recomputing directly is the better choice.
def should_read_cache(prefix_tokens, num_blocks, cost_model):"""Parameters in cost_model must be replaced with measured data;the values here only demonstrate the logic."""recompute_ms = prefix_tokens * cost_model["ms_per_token_compute"]read_ms = num_blocks * cost_model["ms_per_block_read_p99"]# Require read time to be significantly lower than recomputation, with a safety marginreturn read_ms < recompute_ms * cost_model["safety_ratio"]
Note that this uses p99 read latency rather than average read latency, because the decision must serve the tail experience.
2. Align to Blocks and Merge Reads
Block size should align with how computation is chunked. Avoid issuing many small reads for a short prefix—each read carries fixed scheduling and round-trip overhead. Merge read requests wherever possible.
3. Tiered Storage, Local First
Keep high-frequency prefixes close to the compute devices, and place low-frequency prefixes in higher-capacity but slower tiers. Check local storage first, then remote. This reduces cross-node data movement.
4. Overlap Reads with Computation
If the data being read is only needed in the next computation step, issue the read early so data movement runs in parallel with current computation. This requires the scheduler to have a clear understanding of data dependencies.
5. Set Read Deadlines
Set a timeout for reads. On timeout, recompute directly, cutting off the tail amplification caused by slow reads.
from concurrent.futures import ThreadPoolExecutor, TimeoutErrorpool = ThreadPoolExecutor(max_workers=8)def fetch_or_compute(cache, key, deadline_s, compute_fn):future = pool.submit(cache.get, key)try:value = future.result(timeout=deadline_s)if value is not None:return valueexcept TimeoutError:# Note: cancel cannot interrupt a task that has already started;# it only prevents tasks that have not yet started from runningfuture.cancel()return compute_fn()
6. Limit Concurrent Reads
Cap the number of concurrent cache reads to reserve bandwidth and queue resources for compute tasks. The concurrency limit should be determined through load testing, not set by intuition.
7. Rollout and Validation
The reworked cache should go through canary validation before full rollout. Recommended metrics to watch:
- Percentile latency: Observe p50, p95, and p99 together, and check whether p99 returns to or below the pre-cache level.
- Hit rate and effective benefit: Hit rate is only an intermediate metric. What matters more is whether the compute time saved exceeds the extra time spent reading.
- Read timeout rate: A high timeout ratio means the deadline is misconfigured or the storage layer is saturated.
- Rollback switch: Keep the ability to disable the cache with one switch, and verify during the canary phase how quickly it takes effect.
Validation should replay the same request traffic to compare results before and after the change. Traffic differences across time periods can easily distort conclusions.
8. Summary
- A cache’s value depends on the relative size of read cost versus recomputation cost, not on the hit rate itself.
- Small data volume does not mean fast reads. Transfer, copying, queuing, and synchronization all add latency.
- The median cannot reflect tail problems. Judging cache effectiveness requires looking at p95 and p99.
- To locate problems, instrument each stage and group by request characteristics—avoid changes based on intuition.
- The rework directions are: set a benefit threshold, merge reads, use tiered storage, overlap reads with computation, bound waiting time, and control concurrency.
- Before rollout, compare using replayed identical load, and keep a switch that can quickly disable the cache.
