Optimizing State Caching in Hybrid Architectures: 3x Prefill Throughput for Long-Context Workloads
This article explains why prefill, not decode, becomes the bottleneck when hybrid architectures combine full attention layers with linear layers, and how treating the combined KV cache and linear state as a first-class hybrid state cache restores fine-grained reuse. It covers state chunking and chained addressing, tiered storage and scheduling, incremental updates with copy-on-write, the four metrics worth tracking, and a minimal path to adoption. Readers will learn where the reported gains come from and which workloads benefit most.
1. Background: Why Hybrid Architectures Are Becoming the Default for Long Context
A clear trend in recent model design is the move toward hybrid architectures that alternate full attention layers with linear layers. Full attention layers handle precise global information retrieval, while linear layers (state space models and linear attention variants) trade a constant-cost state update for efficient decoding over long sequences. The immediate payoff is lower memory usage and a smaller cache footprint during decoding, which makes long-context inference practical on a single device.
Real workloads, however, are rarely a single long input followed by a single long output. Agentic scenarios such as AI coding tools are characterized by multiple rounds of tool calls, new observations appended each round, and system prompts plus repository context that are reused over and over. Input lengths in these cases often reach tens of thousands to hundreds of thousands of tokens, with a heavily repeated prefix.
2. The Core Conflict: Prefill, Not Decode, Is the Bottleneck
In a pure attention architecture, prefix caching has clean semantics: a token sequence maps to one key-value cache, and a hit lets you skip the repeated computation. Hybrid architectures break that simple correspondence.
The reason is that a linear layer’s cache is not an addressable set of key-value pairs by position. It is a fixed-size state that evolves over time. The entire prefix is compressed into a fixed-length representation, which means:
- Reuse granularity becomes coarse; you cannot partially hit cache blocks the way you can with a KV cache.
- The state is tightly bound to the history that produced it, so once a prefix forks, the state cannot be shared directly.
- Multi-turn appends force the state to be read out, updated, and written back repeatedly, creating obvious read/write amplification.
The result is that the decoding advantage is canceled out by the prefill stage. In multi-turn long-context replay, most of the system’s compute is spent recomputing historical prefixes. Prefill throughput becomes the deciding factor for end-to-end experience, and the p90 tail of time to first token degrades in particular.
3. Redesign: Treat the Hybrid State as a First-Class Cache Object
The direction proposed in the industry is to unify the KV cache and the linear state under a single abstraction, the hybrid state cache, and rebuild three pipelines around it.
The first is state chunking and addressing. Split a long prefix into fixed-length chunks, maintain a self-contained state snapshot for each chunk, and record a content fingerprint for it. The hit test then shifts from “is the whole prefix identical” to “which chunks are identical,” restoring fine-grained reuse.
A sketch of the cache key design:
state_key = hash(parent_state_key, chunk_tokens, layer_type, chunk_index)
Here parent_state_key forms a chained dependency, guaranteeing that a state snapshot corresponds strictly to its historical prefix and preventing incorrect reuse across branches. layer_type distinguishes full attention layers from linear layers, since their cache layouts and update rules are entirely different.
The second is tiered storage and scheduling. Hot states stay resident in device memory, warm states live in a host memory cache pool, and cold states sink to a distributed cache or external storage. The scheduler decides prefetch and eviction based on the probability that a chunk will be reused multiplied by the compute saved by reusing it, rather than simple least recently used.
The third is incremental updates and parallel prefill. After a prefix hit, the state only needs to advance from the first missing chunk onward, and different requests can share the same read-only snapshot. Write-back uses copy-on-write to avoid concurrent requests polluting the same state.
4. Engineering Gains and Observable Metrics
In an experiment replaying real agent trajectories on a single device, this kind of design raised prefill throughput to roughly three times that of a general-purpose inference framework, while p90 time to first token dropped by nearly 90%. The gains still held after attaching a host memory cache on the order of hundreds of gigabytes, which indicates the bottleneck is not determined by device memory capacity alone but by cache management and scheduling policy.
Four metrics are worth tracking when evaluating this kind of optimization: chunk-level cache hit rate, state read/write bytes, prefill throughput, and p90 time to first token. Looking at average latency alone hides the tail problem, and agent experience is precisely what the tail determines.
5. Adoption Advice
To put this into practice in your own inference service, start with a minimal loop: first collect prefix fingerprint statistics on requests to quantify the real reuse rate; then introduce chunk-level state snapshots with copy-on-write; finally extend to a three-tier cache spanning device memory, host memory, and distributed storage. If you run inference on Baidu AI Cloud’s container platform, store cold states in object storage, and track hit rate and tail latency with the monitoring and alerting service, you can stand up an observable validation environment fairly quickly. One caveat: the gains depend heavily on workload characteristics, so scenarios with short inputs and low repetition should carefully weigh the extra management overhead.
