When Cache Reads Are Slower Than Compute: The Hidden Cost of Optimized Inference

    Caching is often treated as a default performance accelerator in large-model inference services — but what happens when reading from cache is actually more expensive than recomputing? This article examines a real-world case where a shared cache layer for a mixture-of-experts (MoE) model caused p99 latency to jump from 3.96 seconds to 17.3 seconds, even though median latency stayed flat. We break down the root causes: synchronization amplification across parallel processes, queuing delays in distributed storage, and the neglected overhead of serializing and transferring multi-megabyte blocks. The article concludes with practical optimization directions, including latency decomposition, a local-first retrieval strategy, and timeout-based fallback mechanisms.

    A Counterintuitive Phenomenon

    In large-model inference services, caching is typically treated as a standard means of speeding up performance. Once the intermediate results of attention computation have been calculated, they can be reused when similar requests arrive, avoiding redundant computation. This reasoning holds in most scenarios — but it carries an implicit assumption: that reading from cache is significantly faster than recomputing.

    A team added a shared cache layer to an inference service running an ultra-large-scale Mixture-of-Experts (MoE) model, used to store attention-related intermediate data. MoE models route different sub-networks to handle different types of inputs, allowing the parameter count to scale without a proportional increase in computation. The service ran on a node equipped with 8 high-performance GPUs.

    The results after deployment were contradictory: median latency barely changed, but p99 latency jumped from 3.96 seconds to 17.3 seconds — roughly 4.4× worse. Tail-end request experience deteriorated significantly, and the team ultimately rolled back the feature.

    This article examines the root cause of this problem and presents a set of actionable optimization approaches. The core conclusion is that cache reads have their own cost, and under high concurrency with synchronous communication, this cost is often underestimated.

    System Architecture at a Glance

    Before diving into the problem, it’s important to understand the key components of the inference system.

    Low-Rank Key-Value Compressed Attention

    The model uses Multi-head Latent Attention (MLA). This mechanism compresses the key-value information of each token into a shared low-rank vector. Regardless of the number of attention heads, the amount of intermediate data stored per token remains fixed and compact.

    In this case, with FP8 precision, every 256 tokens are packed into a single block of approximately 12.4 MB, translating to roughly 48.4 KB per token. The block size directly determines the network and memory overhead of cache reads and writes — a figure that will be referenced repeatedly throughout this analysis.

    Prefill Context Parallelism

    The initial processing of long texts (prefill) is computationally intensive. The system splits a long input across multiple GPUs for parallel processing, and once computation completes, each GPU must exchange results over the network so that all GPUs have the full context.

    This parallelization introduces a critical characteristic: the 8 compute processes (ranks) within a node are tightly coupled. Every synchronization point requires all participants to arrive; if any single process is slow, the remaining processes idle at the barrier.

    Two-Level Cache

    The system implements a two-tier cache:

    • L1: Local memory near the GPU, offering fast access but limited capacity, serving only a single inference instance.
    • L2: A distributed key-value store with large capacity, shared by all inference instances, accessed over the network.

    L1 is analogous to each branch keeping its own local ledger; L2 is the consolidated ledger aggregating all branches. The consolidated ledger simplifies management, but both reads and writes require queuing.

    Symptoms and Root Cause Analysis

    The Divergence Between Median and Tail Latency

    Median latency reflects typical requests, while tail latency reflects the worst-case requests. With caching enabled, typical requests were nearly unaffected, indicating that the hit path did not significantly slow down average throughput. The problem concentrated in the tail, which points toward synchronization and queuing rather than average overhead.

    Synchronization Amplification

    Suppose each process encounters a slow path during a cache read with a probability of 1%. Individually, this seems rare — but all 8 processes must complete before any can proceed:

    • The probability of at least one slow process is 1 - 0.99⁸, approximately 7.7%.
    • The more processes involved, the more frequently tail events surface.

    Consequently, the node-level p99 is effectively determined by the slowest among multiple processes. When cache reads introduce even occasional jitter, the synchronization mechanism amplifies it across the entire node.

    Queuing at Shared L2 Storage

    When 8 inference instances concurrently access the same L2 store, requests queue up at the server side. Under heavy read volume, the wait time per read far exceeds the actual data transfer time. This queuing delay is not obvious in average metrics but shows up prominently in the tail.

    The True Cost of Reading a Block

    To determine whether caching is worthwhile, the two paths should be compared:

    1. Benefit condition: recompute time > cache read time + deserialization time

    For a 12.4 MB block, read latency is determined by network bandwidth, serialization, queuing, and storage response. When the recompute time is already short — or when the network link is congested — reading from cache can be slower than recomputing.

    Optimization Directions

    Once the root cause is clear, the goal is to use the cache only when it is genuinely faster. The following directions work well in combination.

    1. Decompose Latency Before Acting

    Before enabling cache, break down a single request’s latency into components: local computation, L1 lookup, L2 lookup, network transfer, synchronization wait, and deserialization — and record the quantiles for each. Without this breakdown, any optimization is guesswork.

    2. Local First, Remote as Fallback

    The lookup order should be L1, then L2. An L1 hit should never trigger a remote access. For L2, it should only be queried when the request prefix is sufficiently long and the reuse probability is sufficiently high.

    3. Set a Read Budget and Allow Fallback

    Define a timeout for L2 reads. When the budget is exceeded, abandon the read and recompute instead. This prevents cache misses and slow reads from cascading into tail latency events across the entire node.