Hybrid Architecture State Caching: Tripling Prefill Throughput
This article explains why hybrid architectures combining full attention and linear layers have become a common choice for AI agent workloads, and why prefill has emerged as the new performance bottleneck. It details three core designs for hybrid state caching: a unified cache block abstraction with shared prefix hashing and reference counting, layered reuse that distinguishes sliceable key-value chunks from non-sliceable linear states via checkpoints, and heterogeneous eviction driven by reconstruction cost rather than size alone. The article also covers engineering considerations such as precision alignment, memory budgets, observability, elastic scaling, and integration with cloud storage and message queues, followed by guidance on attributing and validating throughput gains.
1. Why Hybrid Architectures Have Become the Default for Agent Workloads
Over the past year, mainstream large model designs have clearly converged on a hybrid structure of full attention layers plus linear layers. The motivation is straightforward: agent workloads routinely involve contexts of tens of thousands to hundreds of thousands of tokens, along with heavy tool calling and multi-turn backtracking. In a pure full attention architecture, the key-value cache (KV Cache) grows linearly with sequence length, so memory and bandwidth quickly become bottlenecks.
The core advantage of linear layers, such as state space models and linear attention, is that inference maintains a fixed-size recurrent state that is decoupled from sequence length. A hybrid architecture assembles the two: a small number of full attention layers preserve precise global retrieval, while the majority of linear layers handle long-range information compression. This trades off decoding speed, cache footprint, and quality.
The cost is that the cache structure shifts from homogeneous to heterogeneous. The full attention portion remains a tensor that grows by layer, by head, and by position, while the linear portion is a fixed-length state that evolves over time. Traditional cache management strategies designed for pure full attention, including uniform eviction, uniform quantization, and uniform swapping, are no longer optimal here and can even consume the benefits of the hybrid architecture.
2. Why Prefill Has Become the New Bottleneck
In agent scenarios, request shapes are heavily input-weighted and output-light: a single request may carry long documents, historical trajectories, and tool return values, while the number of tokens actually generated is small. This means the compute and memory access volume of the prefill stage far exceeds that of the decode stage.
Prefill is a mixed compute-intensive and bandwidth-intensive workload. The attention matrix in full attention layers grows quadratically with length, while linear layers perform a sequential scan token by token, and the two have different preferences for parallelism. Poor cache management leads to three types of waste:
- Redundant computation: identical prefixes such as system prompts, tool definitions, and few-shot examples are prefilled repeatedly.
- State reconstruction: linear states cannot be sliced and reused arbitrarily by position the way key-values can, so even after a prefix hit the state must be recomputed.
- Fragmentation and copying: heterogeneous cache blocks differ in size, and concatenation and swapping in and out create extra memory movement.
The claim of “tripling prefill throughput” does not refer to a single kernel speedup. It refers to end-to-end throughput gains after systematically eliminating the waste above by redesigning the cache abstraction and lifecycle.
3. Three Core Designs for Hybrid State Caching
3.1 Unified Abstraction: Placing Both State Types in One Address Space
The first key step is to define a unified Cache Block abstraction: describe metadata separately for the full attention and linear portions, but share the same prefix hashing and reference counting mechanism. An illustration:
@dataclassclass StateBlock:prefix_hash: str # Hash of prefix content, used for hit detectionattn_chunks: list[Tensor] # Full attention key-value chunks, sliceable by positionlinear_state: Tensor # Fixed-length recurrent state of linear layersref_count: int = 0last_access: int = 0 # Logical clock, used for eviction
Unified addressing means the scheduler does not need to care whether the underlying storage is a sliceable tensor or a non-sliceable state, so a single policy can manage all cache.
3.2 Layered Reuse: Distinguishing Sliceable from Non-Sliceable State
The full attention key-value cache has prefix additivity: after a prefix hit, only the key-values for new positions need to be appended. Linear states lack this additivity because they are the result of historical compression. The reuse strategy must therefore be layered:
- For the full attention portion: share prefixes at block granularity, and skip the attention computation for the corresponding positions on a hit.
- For the linear portion: save state snapshots in the form of checkpoints, and after hitting the most recent checkpoint, replay only a small number of tokens to restore the exact state.
def restore_linear_state(block: StateBlock, replay_tokens: int) -> Tensor:state = block.linear_state.clone()for tok in range(replay_tokens):state = linear_layer.step(state, tok) # Small replay with controlled costreturn state
Checkpoint spacing is a tunable parameter: smaller spacing lowers replay cost but increases storage and copying overhead. In practice, adjusting the spacing dynamically based on access heat yields the most obvious gains.
3.3 Heterogeneous Eviction and Warm-up: Reclaiming by Value Rather Than Size
Traditional LRU only considers time, but a hybrid cache needs a reconstruction cost dimension. Once a linear state is swapped out, reconstruction requires replaying from the beginning, which costs far more than a key-value block. Eviction scoring should therefore combine access frequency, reconstruction cost, and occupied space, prioritizing the retention of states with high reconstruction cost.
Combined with prefetching: in agent trajectories, the next tool to be called and the templates involved are usually predictable, so the key-values and state checkpoints for the corresponding prefixes can be swapped in ahead of time, hiding memory access latency beneath computation.
4. Engineering Implementation Points
- Precision alignment: replay of state checkpoints must keep the numerical path consistent to avoid drift from mixing precisions; storing linear states at higher precision than key-values is recommended.
- Memory budget: set independent quotas and watermarks for the two cache types to prevent fixed-length states from squeezing out sliceable cache space.
- Observability: instrument prefix hit rate, checkpoint replay length, and swap in/out volume, and use monitoring alerts and log services to locate sources of jitter.
- Elastic scaling: scale inference replicas by load level on container platforms; cache hit rate declines as replica count grows, so a cross-replica prefix sharing layer is needed to mitigate this.
- Integration with general cloud capabilities: object storage holds long-lived prefix snapshots, and message queues smooth out request spikes, enabling asynchronous warm-up of “cold prefixes”.
5. Breaking Down the Gains and Validation Methods
The threefold throughput is not the contribution of a single optimization but is decomposable: prefix sharing eliminates redundant prefill, checkpoint reuse reduces linear state reconstruction, and heterogeneous eviction cuts unnecessary movement. Stacked together, these produce a multiplicative effect. For validation, use an offline benchmark with a fixed random seed, measure time to first token, prefill tokens per second throughput, and peak memory separately, and run ablation experiments that disable each optimization one at a time to confirm clear gain attribution.
6. Conclusion
Whether the benefits of a hybrid architecture materialize depends largely on whether the cache layer is redesigned. Bringing heterogeneous states into unified addressing, reusing them in layers according to sliceability, and driving eviction by reconstruction cost is the key path to several-fold prefill throughput gains. For teams building agent platforms, this is both a performance engineering problem and a memory and scheduling architecture problem, and it deserves consideration early in system design.
