Redesigning State Caching for Hybrid Architectures: 3x Prefill Throughput Improvement

    This article explains why hybrid architectures that combine full attention layers with linear or state layers make caching more complex, and presents a practical redesign that treats the mixed state as a first-class citizen. You will learn a four-layer design covering unified addressing with segment fingerprints and version numbers, tiered storage across GPU memory, host memory, and external caches, state snapshots with incremental rollback, and prefill scheduling that prioritizes cache hits. The article also covers deployment on general cloud infrastructure, the main performance gains, and the boundaries of these gains.

    1. Why Hybrid Architectures Make Caching Complex

    A growing number of models now adopt a hybrid structure that combines full attention layers with linear or state layers. The motivation is clear: a small number of full attention layers preserve precise long-range retrieval, while a large number of linear state layers deliver higher decoding throughput and a smaller memory footprint. For single-turn question answering, this is a worthwhile trade-off.

    Real production workloads, however, are rarely single-turn. Multi-turn, long-context scenarios such as intelligent coding tools and code assistants typically have three characteristics:

    1. Extremely long context: repository-level code, multiple files, and tool call results are appended continuously.
    2. A large number of turns: a single task may involve dozens of tool calls and reasoning round trips.
    3. Highly repetitive prefixes: system prompts, project descriptions, and conversation history are almost identical in every turn.

    Under these workloads, the performance bottleneck is usually not decoding but prefill. Every request has to “read” tens of thousands or even hundreds of thousands of tokens again, which significantly increases time to first token (TTFT).

    Cache management for pure attention architectures is relatively mature: the KV cache is a set of tensors that can be indexed by token and partitioned and transferred by block, so a prefix hit is a simple block-level lookup. Hybrid architectures are different. Their state consists of two kinds of heterogeneous data:

    • KV caches produced by full attention layers, which can be appended by token and migrated by block.
    • Recurrent states produced by linear or state layers, which are fixed-size tensors repeatedly overwritten as the sequence advances, and are semantically closer to a “summary” than a per-token record.

    This heterogeneity has three direct consequences: states cannot be sliced by token; state updates are sequentially dependent and cannot be recomputed arbitrarily in parallel; and the two kinds of data naturally have different lifecycles and eviction policies. Reusing cache logic designed for pure attention leads to mismatches such as “the KV cache hits but the state does not” or “the state hits but the KV version does not match,” which ultimately degrades into full recomputation.

    2. Core Design: Treating the Mixed State as a First-Class Citizen

    The key to a workable solution is to unify the KV cache and the recurrent state into a single abstraction called the “mixed state,” and rebuild the cache lifecycle around it. The design can be broken down into four layers.

    2.1 Unified Addressing: Segment Fingerprints Plus Version Numbers

    Compute a content fingerprint for each prefix segment (for example, a rolling hash over the token sequence) and bind it to a state version number to form a globally unique key:

    1. key = hash(prefix_tokens[0:i]) + ":" + state_version

    Reuse is allowed only when both the fingerprint and the version match. This fundamentally prevents silent errors caused by “same structure, different content,” which is the most common pitfall in hybrid architecture caching.

    2.2 Tiered Storage: GPU Hot Tier, Memory Warm Tier, External Cold Tier

    • Hot tier (GPU memory): stores the latest state of active sessions and recent KV blocks.
    • Warm tier (host memory): stores reusable KV blocks and state snapshots for reusable prefixes.
    • Cold tier (external cache or distributed storage): shared across nodes to serve long-lived reuse.

    The point of tiering is not to “store more” but to “swap accurately”: eviction decisions are weighted by state size, hit probability, and recomputation cost, rather than a simple least recently used policy.

    2.3 State Snapshots and Incremental Rollback

    Multi-turn agents often branch: different tool calls are tried under the same prefix. In this case, create snapshot points for the state so that computation can resume incrementally from the most recent snapshot instead of replaying from scratch:

    1. snapshot = cache.checkpoint(prefix_key) # Record the state version
    2. # ... branch attempts ...
    3. cache.restore(snapshot) # Roll back to the snapshot and recompute only the increment

    2.4 Prefill Scheduling: Hit First, Chunked Pipeline

    The scheduler first performs prefix matching and classifies requests into three categories: full hit, partial hit, and miss. For partial hits, it recomputes only the missing suffix, and splits the recomputation into chunks that overlap with state loading to hide I/O and transfer latency.

    3. Engineering Deployment on General Cloud Environments

    The design is vendor-neutral and can be assembled from general cloud capabilities:

    • Compute layer: a container platform hosts the inference service and scales elastically with load.
    • Cache layer: host memory serves as the warm tier, while a distributed cache or object storage serves as the cold tier to enable cross-node state reuse.
    • Governance layer: a logging service records hit rates and recomputation volume, and monitoring and alerting set thresholds for TTFT and memory watermarks.
    • Network layer: state transfer requires attention to bandwidth and serialization overhead; compressing state tensors and transferring them in batches is recommended.

    A useful observable metric for deployment is “prefix hit rate × average reuse length,” which predicts prefill gains better than hit rate alone.

    4. Benefits and Boundaries

    In real long-context trajectory replays, the benefits of this redesign show up in two places: prefill throughput can increase by several times, and p90 TTFT drops substantially. After connecting large-capacity memory or an external cache, cross-session and cross-node reuse further amplifies the gains.

    The boundaries must also be stated: the gains depend heavily on prefix repetition, so workloads with low repetition see limited improvement; loose state version management introduces correctness risks; and tiered caching adds operational complexity. It is therefore advisable to start with a canary rollout in high-repetition scenarios such as coding assistants, validate with both hit rate and TTFT, and then expand the scope.

    The main takeaway for developers is that cache optimization for hybrid architectures is essentially about governing “per-token KV” and “fixed-size recurrent state” together, using fingerprint addressing, snapshot rollback, and hit-first scheduling to turn repeated prefill into a reusable asset.