Read Caching Costs: Why Cache Hits Can Be Slower Than Compute

    A large-scale MoE inference case shows that enabling a shared cache for long-text attention data left median latency almost unchanged but pushed p99 latency from about 3.96 seconds to about 17.3 seconds. This article breaks down the hidden costs of cache reads—index lookup, locking, data copying, layout conversion, bandwidth contention, and scheduling jitter—and explains why cache hits can amplify tail latency. It then presents design practices for treating the read-cache path as a first-class performance path, including sharding, asynchronous overlap, hit-cost budgets, layout alignment, and observability.

    Read Caching Costs: Why Cache Hits Can Be Slower Than Compute

    1. A Counterintuitive Result

    In inference service optimization, caching is often viewed as a free accelerator: as long as there is a cache hit, repeated computation can be skipped. But one team encountered a counterintuitive result while optimizing a very large-scale mixture-of-experts (MoE) inference service.

    They ran the model on a node with eight high-memory accelerator cards and introduced a shared cache layer for long-text scenarios to store attention intermediate data computed earlier. The expectation was that when similar requests arrived again, the data could be reused directly, reducing repeated computation. By intuition, this should lower latency and improve throughput.

    The actual result was different: after enabling the cache, median system latency barely changed, but the slowest 1% of requests—p99 latency—soared from about 3.96 seconds to about 17.3 seconds. The engineering team temporarily rolled back the entire feature.

    The core conclusion of this case can be summarized in one sentence: reading from a cache itself has a cost, and that cost is often severely underestimated in tail-latency scenarios. A cache hit does not mean zero cost. A single hit can include index lookup, concurrency control, data copying, format conversion, bandwidth contention, batch reformation, and scheduling jitter. When these costs stack up with long text, large blocks, high concurrency, and strict SLOs, the cache can turn from an accelerator into a tail-latency amplifier.

    2. First, Understand the Cached Object: Why Blocks Are Large and Hits Are Expensive

    In this case, the model used a compressed multi-head attention mechanism: it compressed the key-value information of each token into a shared low-rank representation, so different attention heads did not need to store full intermediate data separately. This design significantly reduced the amount of data that had to be stored per token.

    At FP8 precision, every 256 tokens were packed into one block. A block was about 12.4 MB, or about 48.4 KB per token on average. Per-token data does not look large, but a long-text request involves many blocks. Once a cache hit requires reading multiple blocks, the read amplification of a single request becomes obvious.

    This means the cache system is not dealing with “a few small objects” but with data that is organized in blocks, substantial in size, and whose access pattern is strongly tied to sequence length. The read-cache cost includes at least:

    • Index lookup: locate the cache entry based on request characteristics, sequence position, and block identifier.
    • Metadata validation: determine whether it is a hit, whether it has expired, and whether it belongs to the same context.
    • Concurrency control: locks or atomic operations when multiple requests read and write the same cache shard at the same time.
    • Data movement: copy data from the cache medium to the compute device, or between different memory tiers.
    • Format conversion: reorder data when the cache layout differs from the layout expected by the compute kernel.
    • Bandwidth contention: cache reads compete for bandwidth with model computation and data transfers from other requests.
    • Scheduling impact: changes in batch structure after a hit can fragment compute batches or cause waiting.

    If only the “saved compute time” is counted, without counting “read-cache time” and “scheduling impact,” cache benefit will be overestimated.

    3. Why Tail Latency Gets Amplified

    Median latency barely changing suggests that the hit path is acceptable for most requests. The p99 spike suggests that a small number of requests trigger long-tail costs under specific conditions. Common amplification mechanisms include:

    1. Serialization of large-block reads. A long-text request needs to read multiple cache blocks. If the hit path performs lookup, locking, copying, and validation serially, the cache-read time for one request grows linearly with the number of blocks.
    2. Read/write contention. The cache must serve hit reads while also handling new block writes and evictions. Under high concurrency, read requests may wait for write locks or eviction locks, making tail requests more likely to be blocked.
    3. Batch fragmentation. Some requests hit the cache and skip part of the computation, so requests in the same batch follow inconsistent compute paths. The scheduler must wait or reshape the batch, stretching tail requests.
    4. Bandwidth spikes. When multiple long requests hit many cache blocks at the same time, cache reads create bandwidth spikes and compete with compute tasks for host-to-device links or inter-card interconnect resources.
    5. Eviction and prefetch interference. A poor eviction policy may evict a block shortly after it is written, while prefetching may consume bandwidth in advance, creating a situation where the hit rate looks decent but hit cost is high.
    6. Missing observability. If only hit rate is monitored and hit latency, lock wait, copy time, and percentile latency are not, it is hard to discover that the cache path has become a tail-latency bottleneck.

    A simplified hit-cost model can be written as:

    1. cache_hit_cost =
    2. index_lookup
    3. + lock_wait
    4. + metadata_validate
    5. + data_copy
    6. + layout_transform
    7. + bandwidth_contention
    8. + scheduling_jitter

    Cache benefit should be expressed as:

    1. net_benefit = saved_compute_time - cache_hit_cost - scheduling_penalty

    Only when net_benefit is consistently positive at the target percentile is caching a real optimization. Looking only at average hit rate can easily lead to wrong conclusions.

    4. Rethinking the Design: Treat the Read Cache as a First-Class Citizen

    To solve this type of problem, it is not enough to increase cache capacity or raise hit rate. The read-cache path must be designed as a performance-critical path.

    1. Shard and Reduce Locking to Cut Concurrency Wait

    Shard the cache index by request or block identifier to reduce global lock contention; use lock-free lookup or read-mostly data structures on the read path where possible; move eviction and writes to independent background paths so they do not block hit reads. The goal of the read path is to be short, direct, and predictable—not feature-rich.

    2. Batch and Overlap Asynchronously

    Combine lookups and reads for multiple cache blocks into batch operations to reduce round trips; issue asynchronous reads before compute depends on the block, overlapping data movement with computation. The key is to set a budget: prefetching must not consume unlimited bandwidth and must be constrained by SLOs and current queue length.

    3. Hit-Cost Budgets and SLO-Aware Scheduling

    The scheduler should not ask only “is it a hit?” but also “will the hit arrive in time?” Maintain an estimated hit cost for each request; when the estimated cache-read cost exceeds a threshold, fall back to recomputation or partial reuse. Pseudocode:

    1. if cache_hit and estimated_read_cost < recompute_cost and queue_delay_ok:
    2. use_cache()
    3. else:
    4. recompute_or_partial_reuse()

    This avoids sacrificing tail latency in pursuit of hit rate.

    4. Block Granularity and Layout Alignment

    Cache block size, alignment, and the layout expected by the compute kernel should be as consistent as possible to reduce copying and reordering. For long text, consider tiered caching: hot short blocks take a low-latency path, while large cold blocks take a capacity-oriented path, preventing all requests from crowding onto the same read path.

    5. Observability: From Hit Rate to Hit Cost

    Monitor at least: hit rate, hit-read latency distribution, lock wait time, bytes copied, bandwidth utilization, eviction frequency, p50/p95/p99 latency of hit requests, and fallback recomputation ratio. Use flame graphs and stage-by-stage breakdowns to locate whether the cost is in lookup, copy, or scheduling.

    5. Practical Checklist

    • Do not validate caching with average latency; look at p95/p99 and SLO attainment.
    • Build a hit-cost model and estimate read amplification by request length and block count.
    • Shard the read path and make it lock-free where possible; move writes to background paths.
    • Give prefetch and asynchronous reads bandwidth budgets and queue constraints.
    • Run dedicated stress tests for batch fragmentation after cache hits.
    • Keep a policy switch for “hit but too slow to read, so fall back.”
    • Include both hit rate and hit cost in capacity planning.

    6. Conclusion

    Caching is not a free lunch. It saves compute but consumes lookup, concurrency control, data movement, bandwidth, and scheduling determinism. For very large MoE and long-text inference services, cache blocks are large, request paths are long, and tail latency is sensitive, so read-cache costs are more likely to be amplified.

    The right response is not a simple rollback or blind capacity expansion. Treat the read-cache path as part of an end-to-end cost model: quantify hit cost first, then design sharding, asynchronous execution, batching, fallback, and observability mechanisms. Only when both median and tail latency improve has caching truly moved from “looks useful” to “production-ready.”