When Caching Is Slower Than Compute: The Hidden Cost of LLM Inference Optimization

    This article examines a counterintuitive performance failure in a large-scale Mixture-of-Experts (MoE) inference service: adding a shared KV cache left median latency flat while pushing p99 latency from 3.96 seconds to 17.3 seconds. It breaks down the real resource cost of caching across capacity, bandwidth, and concurrency contention, explains why cheap compute makes saved prefill work less valuable than the memory bandwidth it consumes, and details four mechanisms that amplify tail latency. It then presents a practical remediation path: admission control based on expected gain versus cost, a tiered hot/warm/cold layout with sharding and chunked storage, fully asynchronous and preemptible transfers, and bucketed observability metrics. The takeaway for inference teams is that any optimization must account for its own cost, and sometimes the most professional choice is not to add the cache layer at all.

    When Caching Is Slower Than Compute: A Performance Assumption Turned Upside Down

    1. Incident Review: p50 Stayed Flat, Tail Latency Quadrupled

    An inference service team at a cloud provider was maintaining a very large Mixture-of-Experts (MoE) model when they ran into a counterintuitive result. In an MoE model, the network is split into multiple “experts,” and each token activates only a few of them, which allows the parameter count to grow without the compute cost growing linearly.

    The service ran on 8 high-performance accelerators on a single node and mainly served long-context workloads. To reduce time-to-first-token for long contexts, the team added a shared cache: attention intermediates already computed for earlier requests (Key/Value tensors and similar) were stored and reused whenever an incoming request shared an identical or highly similar prefix, eliminating redundant computation.

    The post-launch numbers were bad:

    • Median latency (p50) barely moved;
    • The slowest 1% of requests (p99) jumped from 3.96 seconds to 17.3 seconds;
    • Throughput showed no meaningful gain, while memory usage went up.

    The team’s first instinct was a full rollback. But a rollback only hides the problem. The question actually worth answering is this: reading from a cache has a cost of its own, and that cost was systematically underestimated during capacity planning.

    2. Understand How the Model Consumes Memory Before Discussing Caching

    To see where the cost comes from, you first have to look at the resource structure of the system. Models like this typically use a low-rank compressed attention mechanism (each token’s key/value information is compressed into a shared low-dimensional latent vector). The benefit is that the amount of intermediate data stored per token is fixed and small, regardless of how many attention heads there are.

    That leads to a highly misleading inference: “If each token is so cheap, the cache must be cheap too.” The real resource bill has three line items:

    1. Capacity: number of cache entries × bytes per token × average context length. For long-context workloads, length is a multiplicative variable.
    2. Bandwidth: every hit requires moving tensors from device or host memory back to the compute units, and the transfer volume grows linearly with length.
    3. Concurrency contention: cache reads and writes share the same memory bandwidth and the same copy engines as the inference batches already running.

    An illustrative capacity estimate (numbers are for demonstrating the method only):

    1. bytes_per_token = 576 # latent vector dimension x bytes per precision
    2. tokens_per_entry = 32768 # typical long-context length
    3. entries = 4096 # number of sessions we want to cache
    4. cache_bytes = bytes_per_token * tokens_per_entry * entries
    5. print(cache_bytes / 1024**3) # roughly 72 GiB

    What does 72 GiB mean inside one accelerator’s memory? It means the space available for KV is heavily squeezed, dynamic batch sizes are forced down, and queueing time goes up. The cache did not save compute; it moved the cost from compute capacity onto memory capacity and memory bandwidth.

    3. Why the Compute You Save Is Cheap and the Bandwidth You Spend Is Expensive

    Low-rank compression keeps each individual cache entry small, but the bottleneck in inference is often not floating-point math—it is data movement. The cost of a request can be roughly written as:

    1. T_request ≈ T_prefill_compute + T_kv_write + T_queue
    2. T_hit ≈ T_lookup + T_kv_read + T_queue'

    The benefit of a hit is that T_prefill_compute is avoided; the cost of a hit is T_lookup + T_kv_read. When the context is long and prefill is already cheap thanks to the compression design, T_kv_read can easily exceed the portion that was saved. That is the arithmetic behind “the cache is slower than compute.”

    The more troublesome term is T_queue': the cache occupies memory and bandwidth, which reduces how many requests can run in parallel at the same moment and pushes queueing time up. p50 stayed flat because most requests take the short-context, low-hit path. p99 exploded because long context + cache miss + high concurrency happened at the same time: the system had to pay full prefill, pay the cache management overhead, and wait in a crowded queue.

    4. Four Mechanisms That Amplify Tail Latency

    1. A miss is not free: index lookup, prefix comparison, and invalidation checks all have to run, so the miss path is actually longer.
    2. Synchronous transfers block the main path: if the tensor copy after a hit runs on the same stream as compute, a “time-saving” operation becomes a wait on I/O.
    3. Eviction thrashing: when capacity is insufficient, the cache repeatedly loads and evicts; long sessions are pushed out just after being built, so both hit rate and overhead lose.
    4. The knock-on effect of memory eviction: less available KV space → smaller batches → lower throughput → longer queues → amplified tail latency.

    5. The Fix: Turn “Should We Cache?” into a Computable Question

    5.1 Do an Admission Check Instead of Enabling by Default

    Keep a cache entry only when the expected benefit clearly outweighs the cost:

    1. def should_cache(ctx_len, hit_prob, prefill_cost, read_cost, mem_pressure):
    2. gain = hit_prob * prefill_cost(ctx_len)
    3. cost = read_cost(ctx_len) + mem_pressure_penalty(mem_pressure)
    4. return gain > cost * 1.5 # safety margin to avoid borderline thrashing

    The more robust engineering approach is to roll out gradually by request profile: short contexts bypass the cache entirely; only very long contexts with a stable prefix (fixed system prompts, multi-turn question answering over long documents) enter the cache candidate set.

    5.2 Replace a Single Shared Pool with a Tiered Layout

    • The hot tier sits in device memory next to the compute units and holds only a small number of high-hit entries;
    • The warm tier sits in host memory and relies on asynchronous prefetch to move data ahead of time;
    • The cold tier falls back to object storage or a distributed cache, enabled only for sessions that can tolerate high latency.

    This is paired with a sharding and replication strategy: shard by session hash so no single node becomes a bandwidth hotspot; store very long entries in chunks so reads can happen on demand and block by block instead of moving everything at once.

    5.3 Make Transfers Fully Asynchronous and Preemptible

    The core principle: a cache read must never block the main inference path. Hit data is injected as “available for a future batch,” and if the current batch cannot make it in time, it automatically degrades to a miss; copy tasks get timeouts and priorities, and give way to real requests when the queue is tight.

    1. batch N : prefill(request A) -> submit async prefetch (A's KV)
    2. batch N+1 : hit if prefetch finished, otherwise handle as a miss

    5.4 Observability: Turn the Hidden Cost into Metrics

    The metric to monitor is not “hit rate” alone, but a set of them:

    • Hit rate bucketed by context length (what are p50/p90/p99 in each bucket);
    • Read latency and bytes moved per hit;
    • The drop in batch size caused by cache occupancy;
    • The extra overhead on the miss path;
    • Eviction rate and recompute rate.

    With these, you can answer the key question: who exactly is this cache layer saving time for?

    6. Conclusion

    The real lesson from this incident is not “caching is useless,” but that any optimization must count its own cost in the model. In inference systems where compute is cheap and bandwidth and capacity are expensive, the cost of reading a cache is routinely underestimated by intuition, and on tail requests that underestimation is multiplied by concurrency and capacity pressure.

    For teams running inference services, the practical order of judgment is: quantify the capacity and bandwidth bill first, then make an admission decision, then use tiering and asynchrony to spread the cost out, and finally keep validating with bucketed metrics. If the numbers do not show a clear benefit, the most professional optimization is often—not adding this layer.