Optimizing State Caching in Hybrid Architectures: Up to 3x Higher Prefill Throughput
This article explains why hybrid architectures that combine linear attention layers with full attention are becoming the default in open-source LLM design, and why they make cache management harder for coding agent workloads. It breaks down the fundamental lifecycle differences between KV caches and recurrent states, then walks through a redesign based on unified addressing, block-boundary snapshots, tiered storage, and recompute-versus-load cost tradeoffs. Reported results show up to 3.14x prefill throughput and up to 88.4% lower p90 time-to-first-token, along with practical deployment recommendations.
1. Hybrid Architectures Go Mainstream: Combining Linear Layers with Full Attention
In open-source LLM designs over the past two years, linear attention and state space layers have shifted from experimental components to standard building blocks. Mechanisms such as Kimi Delta Attention, Gated DeltaNet, and Mamba-2 share a common trait: during inference they no longer need to store key-value pairs that grow linearly with sequence length. Instead, they maintain a fixed-size recurrent state. These are typically paired with a small number of full attention layers that preserve precise global retrieval.
The popularity of this “full attention + linear layers” hybrid stack comes down to three reasons:
- Controllable decoding cost. Each decoding step in a linear layer is a constant-time state update, so decoding overhead barely grows with context length.
- Significantly lower cache footprint. Fixed-size states replace per-token KV caches, greatly reducing memory pressure.
- Long-context capability is preserved. A few full attention layers handle precise lookback, avoiding the retrieval degradation seen in purely linear models.
Several recently released open-source model families have adopted this approach, turning hybrid architectures from an optional optimization into a default choice.
2. What Makes Coding Agent Workloads Different: Why Cache Management Suddenly Gets Hard
Hybrid architectures deliver clear gains on single-turn short requests, but coding agents have a very different workload profile:
- Multi-turn accumulation: A single session can involve dozens of tool calls, each carrying the full prior history.
- Highly overlapping prefixes: System prompts, repository context, and prior patches repeatedly appear at the start of requests.
- Long context: Whole-repository retrieval results, long logs, and multi-file diffs can easily push a single request past 100K tokens.
- Long-tail latency: p90 and p99 latency shape the user experience, not average latency.
Under this workload, the cache hit rate directly determines the actual compute spent in the prefill stage. And in hybrid models the cache is no longer a single object, which is the root of the complexity.
3. The Core Conflict: Two Cache Types with Fundamentally Different Lifecycles
A pure Transformer KV cache is appended token by token, so the cache for any prefix is a reusable, valid intermediate state. Hybrid architectures instead maintain two kinds of state:
| Dimension | Full Attention KV Cache | Linear Layer Recurrent State |
|---|---|---|
| Size | Grows linearly with sequence length | Fixed size, independent of length |
| Update method | Append writes | In-place overwrite |
| Reuse granularity | Any token boundary | Depends on when state snapshots are persisted |
| Invalidation behavior | Still usable after truncation | Irreversible once overwritten by later tokens |
The conflict is that recurrent states are path-dependent: they can only be reused at a position where a snapshot was explicitly taken, whereas KV caches naturally support splitting at any position. If you reuse the “block-wise caching + prefix matching” strategy designed for pure attention, recurrent states get recomputed extensively, while snapshots waste memory and bandwidth.
4. Redesign Approach: Treat State as a First-Class Cache Object
Common industry practice for prefill optimization can be abstracted into four actions:
(1) Unified addressing. Build consistent keys for both cache types: address KV caches by content-hashed blocks, and address state snapshots by “owning block boundary + state version,” so the scheduler can query both with the same matching logic.
(2) Snapshot at boundaries. Snapshot the linear state only at block boundaries, not within blocks, to avoid frequent persistence. Example logic:
# Pseudocode: block-boundary-driven hybrid cachefor chunk in split_by_block(tokens, block_size=256):prefix_hit = kv_index.lookup(chunk.hash) # KV cache can hit on any blockstate_hit = state_index.lookup(chunk.boundary) # state can only hit at boundariesif state_hit:state = state_hit.restore() # restore recurrent state directlyelse:state = advance(state, chunk) # recompute from the nearest snapshotif chunk.is_boundary:state_index.store(chunk.boundary, state.snapshot())kv_index.append(chunk.kv)
(3) Tiered storage. Keep the hottest states and recent KV blocks in GPU memory, medium-hot snapshots in host memory, and cold cross-session, cross-node data in remote shared storage. Because state snapshots are fixed in size, they are especially well suited to high-latency, high-capacity tiers.
(4) Trade off recompute against load cost. The scheduler must compare the transfer time of loading a snapshot from remote storage against the compute time of recomputing from a nearer snapshot, and pick the cheaper option. This decision dimension does not exist in pure attention scenarios.
5. Results and Engineering Benefits
A public evaluation that replays real coding tool traces on a single accelerator card shows that, compared with a general-purpose inference framework baseline, the redesigned hybrid cache scheme reaches up to roughly 3.14x prefill throughput and reduces p90 time-to-first-token by up to about 88.4%. The gains hold after adding host memory caching on the order of hundreds of GiB, and the design supports distributed storage and cross-node state reuse.
The benefits break down into: saved linear layer recomputation after hitting a fixed-size state, lower scheduling overhead from block-level matching, and significant p90 convergence as long-tail requests are absorbed by the cache.
6. Deployment Recommendations
- Quantify prefix overlap first. Workloads with overlap below a threshold are not good candidates for state caching investment.
- Load-test block size. Too small produces too many snapshots; too large makes matching granularity coarse.
- Always version state snapshots. Old snapshots must be invalidated after model weight or configuration changes.
- Prioritize observability. Hit rate, recompute volume, and load wait time should be part of logging, monitoring, and alerting.
- Pair with elastic scaling. Deploy the cache layer and inference layer decoupled on a container platform so each can scale independently with load.
Managing state caches in hybrid architectures is essentially about bringing path-dependent recurrent states into a caching system originally designed for arbitrarily splittable key-value pairs. Understanding the lifecycle differences between the two state types is the prerequisite for achieving several-fold prefill acceleration.
