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

    This article explains why prefix caching is harder in hybrid architectures that alternate full attention layers with linear or state-space layers, and how a redesigned layered cache addresses the problem. It covers the failure modes of the two state types, checkpoint density trade-offs, scheduler mismatches, and tiered storage consistency costs. The proposed design uses unified prefix addressing, adaptive checkpoints, reversible state compression, fused prefill operators, and cross-node reuse. Reported results show about 3.14x prefill throughput and up to 88.4% lower p90 time-to-first-token, along with practical capacity planning guidance.

    1. Why Hybrid Architectures Dominate Long-Context Workloads

    Recent model design trends have widely adopted hybrid architectures that alternate full attention layers with linear or state layers. The motivation is clear: full attention layers handle precise global information retrieval, while linear layers—including various linear attention and gated state-space layers—trade constant-cost state maintenance for higher decoding efficiency and a smaller cache footprint. For long-context, high-concurrency scenarios, this structure offers a near-decisive advantage in memory budget and decoding speed.

    The engineering cost, however, has long been underestimated. In traditional attention-only models, prefix caching only needs to store a single token-indexed key-value tensor, making hit detection, eviction policies, and cross-request sharing relatively simple. Hybrid architectures maintain two distinct state types at once: an attention key-value cache that grows linearly with sequence length, and a recurrent state that is continuously compressed and rewritten as layers advance. The latter folds all history so far into a fixed-size tensor, has no natural token-level boundary, and turns prefix reuse from a lookup problem into a state-alignment problem.

    Coding agents are the workload that amplifies this tension the most. Multi-turn tool calls, codebase retrieval, failed retries, and context rollbacks cause requests to share large identical prefixes while also producing frequent branches and backtracking. Whoever manages state caching well under this workload can significantly reduce time-to-first-token.

    2. Root Causes: Why Prefix Caching Is Harder for Hybrid Models

    2.1 The two state types fail differently

    The attention key-value cache is truncatable: a hit on k tokens lets you reuse the cache for those k tokens and continue computing the rest. The linear state is not truncatable: it can only be reused in full when two requests share an exactly identical prefix with no intervening state updates. Once a branch occurs, replay must restart from the most recent reusable checkpoint.

    2.2 Checkpoint granularity versus memory usage

    If checkpoints are too dense, the storage cost of fixed-size states grows quickly and cancels out the memory advantage of the hybrid architecture. If they are too sparse, the number of tokens that must be replayed after a branch spikes, pushing prefill computation back up. This is a classic space-versus-recompute trade-off.

    2.3 Scheduler mismatch

    Most inference framework schedulers measure resources in tokens, while the real constraint for hybrid states is the number of state slots. When a scheduler admits requests based on a token budget, it can exhaust state slots while memory is still available, causing head-of-line blocking and tail-latency jitter.

    2.4 Consistency cost of tiered storage

    Offloading cold states to host memory or remote storage expands capacity, but state blocks are more sensitive than key-value blocks: any incomplete write-back can corrupt subsequent reuse, requiring stricter transactional and validation mechanisms.

    3. Design: A Layered Cache System for Hybrid States

    3.1 Unified addressing with a shared prefix identifier

    A practical approach is to compute an incremental hash over the request prefix, forming a hierarchical chain of block identifiers, while recording the attention cache range and a snapshot pointer for the linear state at each block. Hit detection first checks a lightweight index, then validates the state version number to avoid incorrect reuse.

    1. class PrefixNode:
    2. block_hash: bytes # Content hash of the prefix block
    3. kv_range: tuple[int, int] # Token range of the attention cache
    4. state_ptr: int # Snapshot handle for the fixed-size state
    5. version: int # State version, incremented after write-back completes
    6. parent: bytes | None # Parent block hash, forming the prefix chain

    3.2 Adaptive checkpoints

    Dynamically set snapshot density based on branch probability: sample sparsely at highly divergent points such as tool-call returns and code retrieval results, and densely for stable long prefixes such as system prompts and repository descriptions. The goal is to keep the average replay length within a configurable upper bound.

    3.3 State compression and quantization

    Fixed-size states typically have a more concentrated numerical distribution than the key-value cache, so lower-bit quantization or low-rank compression can be applied before offloading. Compression must be reversible or have bounded error, and the compression format must be marked in the version number to prevent cross-format reuse.

    3.4 Prefill operator optimization

    Fuse hit reuse and miss recomputation into the same batch to reduce kernel launches and intermediate tensor round-trips. Pipelining the replay portion in chunks so computation overlaps with state loading is one of the key sources of throughput improvement.

    3.5 Distributed and cross-node reuse

    Place state blocks in a shared cache pool using content addressing, with nodes cooperating in a “central index, local data” manner. For cross-node reuse, migrate the smaller state snapshots first, and rebuild the key-value cache locally whenever possible.

    4. Results and Capacity Planning

    In public experiments replaying real coding-agent tool traces on a single high-performance accelerator, this type of redesign achieved roughly 3.14x prefill throughput over a conventional implementation, with p90 time-to-first-token dropping by up to about 88.4%. The gains held after adding hundreds of GiB of host memory as a second-tier cache, indicating the bottleneck has shifted from compute to state scheduling and the storage hierarchy.

    Three points matter in practice. First, include state slots in the scheduling budget and use them for admission control alongside memory and concurrency. Second, define observability metrics for checkpoint overhead, including hit rate, average replay length, and state swap-in/swap-out bandwidth. Third, in environments such as Baidu AI Cloud, run inference services on a container platform, store cold states in object storage, and use monitoring, alerting, and logging services to observe tail latency, forming a rollback-capable capacity strategy.

    5. Conclusion

    The benefits of hybrid architectures do not automatically carry over to the serving layer. Treating the attention cache and the linear state as two heterogeneous resources and orchestrating them together—combined with adaptive checkpoints, reversible compression, and tiered storage—is what truly delivers low latency and high throughput under multi-turn, long-context workloads.