Hybrid Architecture State Caching Optimization: 3x Higher Prefill Throughput
This article explains why prefix caching is harder to manage in hybrid architectures that mix full attention with linear attention, gated convolution, or state space layers. It breaks down the conflicts in granularity, invalidation propagation, and lifecycle between attention states and linear-layer states, then presents a redesign built on four principles: heterogeneous chunking with state snapshots, unified content-addressed keys, minimal recomputation point selection, and tiered storage with differentiated eviction. Engineering guidance covers metadata, asynchronous prefetching, serialization, observability, and scheduling. In replay experiments of real AI coding tool sessions on a single high-end accelerator, the design reached up to 3.14x prefill throughput and reduced p90 time-to-first-token by up to 88.4%, with clear boundaries on where the gains apply.
1. Background: Why Hybrid Architectures Are Becoming the Default for Long-Context Inference
A clear trend has emerged in mainstream LLM architectures over the past two years: standard full attention layers are now interleaved with linear attention, gated convolution, or state space layers, forming a hybrid structure of “full attention + linear layers.” The motivation is straightforward. The cache of a full attention layer grows linearly or even quadratically with context length, while the inference state of a linear layer is largely decoupled from sequence length. After mixing the two, the cache that must be moved at each decoding step becomes significantly smaller, decoding is faster, and memory pressure under long contexts is more manageable.
The benefits, however, come at a cost. When the workload shifts from “single-turn question answering” to forms such as “coding agents,” requests take on three distinct characteristics:
- Multi-turn: a single task often involves a dozen to several dozen rounds of tool calls and code re-reads;
- Long context: repository files, error stacks, and retrieved snippets keep accumulating, with prefixes easily reaching hundreds of thousands of tokens;
- High prefix overlap: adjacent turns share a large amount of identical prefix, with only a small amount of content at the tail changing.
Under this kind of workload, the key metric is no longer raw decoding speed, but the hit rate of the prefix cache and prefill efficiency. And this is precisely where hybrid architectures are harder to get right than pure attention models.
2. Why Prefix Caching Is Harder in Hybrid Architectures
A pure attention model has only one form of cache: key-value tensors organized by layer and by head, with a unified addressing scheme and a block granularity that aligns naturally. A hybrid architecture, by contrast, holds two kinds of state at the same time:
- Attention state: corresponds one-to-one with specific token positions, and can be chunked and loaded on demand;
- Linear-layer state: a fixed-size tensor that is “compressed” as the sequence advances, semantically dependent on the entire prefix, and not easily split by token blocks.
This creates three concrete conflicts.
First, inconsistent granularity. Attention state can be reused by block, while linear state can only be reused as a whole. If a unified block-based management scheme is applied to both, it produces substantial internal fragmentation and wasted data movement.
Second, different invalidation propagation. Once the tail of the prefix changes, the attention state only needs to recompute the blocks corresponding to the tail; the linear state, however, must replay from the point of change and advance again, at a cost proportional to “the length before the point of change.”
Third, different lifecycles. Attention state is large and has high reuse value, making it suitable for long-term residency; linear state is small but expensive to recompute, making it a better candidate for priority retention. Managing both with the same eviction policy inevitably trades one off against the other.
3. Redesign Approach: Treat Both State Types as First-Class Citizens
A redesign of the hybrid state cache can be summarized in four principles.
3.1 State Layering and Heterogeneous Chunking
Abstract the cache into two kinds of objects, “attention blocks + state snapshots,” each using a chunking strategy that fits it: the attention side keeps fixed token blocks, while the linear side persists a fixed-size state snapshot at fixed intervals in the form of checkpoints, forming a jumpable chain of states. Illustration:
prefix: [ attn blocks ][ attn blocks ][ attn blocks ] ...state : (s0)----(s1)--------(s2)----------(s3) ...^ record a fixed-size state snapshot every K tokens
3.2 Unified Addressing and Content Hashing
Both kinds of objects share one content-addressed key scheme: compute an incremental hash over the prefix token sequence, using a “block hash” for attention blocks and a “prefix hash + checkpoint index” for state snapshots. This way the same cache entry can be hit across requests, across turns, and across nodes, without relying on session stickiness.
3.3 Minimal Recomputation Point Selection
On a hit, there is no need to replay from the oldest checkpoint. Instead, choose the cached checkpoint that is “closest to the point of change” among all available checkpoints, minimizing the recomputation length. This is the core lever for latency optimization.
3.4 Tiered Storage and Differentiated Eviction
Keep the hottest data in GPU memory, with host memory and a remote cache pool absorbing warm and cold data. When evicting, assign different weights to the two object types: linear state is more “eviction-resistant” because recomputation is expensive, while attention blocks are swapped out earlier because of their size.
4. Engineering Implementation Notes
- Metadata first: maintain reference counts, hit counts, and hash indexes for every block and snapshot; the metadata service must support high-concurrency point lookups.
- Asynchronous prefetching: before the previous round of generation finishes, predict the next round’s prefix based on tool call patterns and pull attention blocks and state snapshots into GPU memory ahead of time.
- Transfer and serialization: fixed-size state is well suited to zero-copy and batched transfer, while attention blocks are best packed per block to reduce small-message overhead.
- Observability: instrumentation should cover hit rate, checkpoint rollback distance, prefill token throughput, and p90/p99 time-to-first-token, so it is easy to tell whether an issue is a hit problem or a scheduling problem.
- Coordination with scheduling: feed “prefix overlap” into routing and batching as an input, so that requests with high overlap land on the same instance; the payoff is far greater than simply scaling out.
5. Results and Applicability Boundaries
In an experiment replaying real AI coding tool session traces on a single high-end accelerator, the redesign above reached up to roughly 3.14x the prefill throughput of a general-purpose inference framework, and reduced p90 time-to-first-token by up to about 88.4%. The gains held after attaching a host memory cache on the order of hundreds of GiB, and the approach extends to distributed caching and cross-node state reuse.
It should be stated objectively that the gains depend heavily on workload characteristics: the higher the prefix overlap and the more turns, the more pronounced the benefit; for single-turn short requests, the improvement is limited. In addition, the checkpoint interval K is a key hyperparameter. Too small, and metadata overhead and write amplification rise; too large, and rollback recomputation becomes longer. It is recommended to use the “distribution of change points” in real traces as the basis for an offline sweep, then fix the value.
6. Conclusion
The “hybrid” in a hybrid architecture should not stop at the model layer; caching and scheduling need hybrid governance as well. Modeling attention state and linear state in layers, unifying addressing, recovering from the minimal recomputation point, and applying tiered storage are the keys to unlocking prefill potential under long-context agent workloads. For teams building AI coding assistants or long-session inference services, this approach maps directly onto their own inference services and cache clusters, with controllable implementation cost and quantifiable gains.
