Hybrid Architecture State Caching: Tripling Prefill Throughput
This article examines why prefix cache management becomes significantly harder in hybrid architectures that interleave full attention layers with linear or state space layers, especially under multi-turn, long-context coding agent workloads. It explains the structural mismatch between position-indexed attention caches and fixed-shape recurrent states, then walks through a decoupled design based on paged attention caching, segment-level recurrent state reuse, prefix trees with interval indexing, tiered storage across GPU memory, host memory, and remote caches, and cross-node consistency. The article also breaks down where prefill throughput and p90 TTFT gains come from and offers practical guidance on baselining metrics, tuning segment length and block size, eviction policies, observability, and decoupling the cache layer from upper-level frameworks.
1. Background: Hybrid Architectures Are Attractive, but Cache Management Gets Harder
Over the past year, mainstream large model architectures have shown a clear trend: instead of relying purely on full attention, they interleave full attention layers with linear or state space layers to form hybrid architectures. The motivation is straightforward. The inference state size of linear layers is independent of sequence length, and the compute and memory access cost per decoding step is roughly constant. As a result, hybrid designs can significantly reduce KV Cache usage and speed up decoding in long-context scenarios.
However, when the workload shifts from single-turn long-document question answering to multi-turn, extremely long-context, tool-call-heavy scenarios such as coding agents, a problem surfaces: prefix cache management for hybrid models is far more complex than for pure Transformers.
The reason is that the two layer types have completely different state semantics:
- The cache for full attention layers consists of key-value pairs indexed by token position. It naturally supports truncated reuse: if a prefix of a given length is a hit, a cache of exactly that length can be reused directly.
- The cache for linear layers is a fixed-shape recurrent state that compresses the entire history into a fixed-size tensor. This state cannot be sliced by position or simply concatenated.
This creates a structural conflict: the attention portion can be reused block by block, while the state portion can only be reused in full. When two requests share prefixes of different lengths, the cache hit granularity is forced to align to the coarsest dimension, wasting a large amount of computation that could otherwise be reused.
2. Why Coding Agent Workloads Amplify the Problem
Coding agent traces have a few distinctive characteristics that make them a stress test for hybrid architecture caching:
- Multi-turn accumulation: a single task often involves a dozen to dozens of tool calls, with each turn appending new observations to the context.
- Highly overlapping but unevenly sized prefixes: later turns in the same session share most of the history, but the shared boundary keeps shifting right as turns progress; different sessions often share common prefixes such as system prompts, coding conventions, and repository documentation.
- Branching and rollback: agents frequently need to go back to an earlier step and try a different approach, forming a tree-shaped rather than linear prefix structure.
- Sensitivity to first-token latency: in interactive experiences, p90 TTFT matters more to user perception than average TTFT.
Under this kind of workload, if the cache system can only do full-state reuse or reuse aligned to the longest common prefix, a large amount of repeated prefill (recomputation) occurs, and GPU compute is wasted on tokens that have already been processed.
3. Core Design Idea: Manage the Two State Types Separately
A class of solutions that has recently emerged in the industry (referred to generically in this article as hybrid state caching) answers the problem this way: do not force a unified reuse granularity for the two state types. Instead, manage them separately, place them in tiers, and rebuild on demand.
3.1 State Tiering: Separate Attention Caches from Recurrent States
Split the cache explicitly into two layers:
- Paged attention cache: managed in fixed-size blocks, supporting block-level hits and block-level eviction, with a block table recording the mapping from logical positions to physical blocks.
- Fixed-length recurrent state: stored in units of segments, where each segment corresponds to the state compressed from a contiguous token interval.
The key point is that although the recurrent state is fixed-length, it corresponds to a definite token interval. Therefore, an interval-to-state index can be built, rather than storing only one copy per session.
3.2 Prefix Tree Plus Interval Index: Partial Hits and Branch Reuse
Use a prefix tree to organize sessions and branches, with each edge labeled by a token interval. Each node carries two kinds of references: a list of attention blocks and a recurrent state handle. On lookup, first find the longest matching path in the prefix tree, then compute the hit boundary for each cache type separately.
Illustrative data structure (pseudocode):
class Node:children: dict[int, Node] # key: next token idattn_blocks: list[BlockHandle] # paged attention cachestates: dict[int, StateHandle] # key: segment end position -> recurrent stateseg_end: int # end of the token interval for this nodedef lookup(root, tokens):node, matched = root, 0for t in tokens:if t not in node.children:breaknode = node.children[t]matched += 1# attention cache can reuse matched tokens# recurrent state needs the nearest seg_end <= matchedreuse_state_pos = max(p for p in node.states if p <= matched)return matched, reuse_state_pos
The significance of this logic is that the attention portion reuses as much as possible, while the state portion falls back to the most recent available segment. The gap in between is filled with one small-scale recomputation rather than a full recomputation.
3.3 Keeping the Cost of State Recomputation Controllable
Because the linear layer state is fixed-length, the cost of recomputing from position a to position b depends only on (b - a), and there is no need to store the key-value pairs of all intermediate tokens. In engineering practice, segment length can be a tunable parameter: shorter segments give finer hit granularity but larger index and storage overhead, while longer segments do the opposite. In practice, segment length is usually on the order of a few hundred to a few thousand tokens, tuned according to the prefix length distribution of the workload.
3.4 Tiered Storage: GPU Memory to Host Memory to Remote Cache
The three data types (attention blocks, recurrent states, and metadata indexes) differ greatly in size and are suited to tiered placement:
- GPU memory: hot data serving the active requests of the current batch.
- Host memory: warm data handling session-level reuse, with capacity reaching hundreds of GiB.
- Remote or distributed cache: cold data and cross-node sharing, used for session migration and task rescheduling.
For scheduling, use a bidirectional prefetch and write-back pipeline: when a remote hit occurs, fetch asynchronously and backfill the upper tier; on eviction, demote data based on reference counts and last-use time to avoid thrashing.
3.5 Cross-Node Reuse and Consistency
In distributed settings, three problems must be solved. First, index consistency: prefix tree metadata must be synchronized with low latency. Second, state integrity verification: use a lightweight fingerprint (for example, hashing the interval tokens and the state) to confirm reusability. Third, concurrent write conflicts: use node-level write locks and copy-on-write to prevent branches from polluting each other.
4. Where the Gains Come From
In this kind of design, the improvement in prefill throughput does not come from a single optimization but from three combined factors:
- Reduced repeated prefill: partial hits replace full recomputation, directly saving compute.
- Better batching efficiency: after a hit, the remaining tokens to compute are fewer and more uniform in length, so batch fill rate increases and GPU utilization rises.
- Less memory movement: tiered placement keeps large cold data out of GPU memory, reducing swap-in and swap-out.
The improvement in the tail of first-token latency comes mainly from factors 1 and 3: p90 cases are often requests with a very long prefix that is only slightly short of a full hit, where partial hits deliver the most obvious benefit.
5. Engineering Recommendations
- Establish a metrics baseline first: separately track average and p90 TTFT, prefill token counts, cache hit rate, and GPU memory usage, so that averages do not hide the tail.
- Tune segment length and block size together: the two jointly determine hit granularity and metadata overhead, and should be set based on the prefix length distribution of real traces.
- Differentiate eviction policies by type: attention blocks can be evicted block by block, while recurrent states are best retained by session reference count to avoid frequent rebuilding.
- Observability is not optional: turn the hit position distribution and the state recomputation interval length distribution into monitoring metrics, so the bottleneck of the gains can be located.
- Decouple from upper-level frameworks: the cache layer is best implemented as an independent service or module, interfacing with the inference engine and scheduler through standard interfaces, so it can scale elastically on container platforms and object storage.
6. Summary
Hybrid architectures trade state compression for smaller caches and faster decoding, but shift the complexity to the cache management layer. The solution is not to revert to a unified granularity, but to acknowledge the semantic differences between the two state types: reuse attention caches block by block and recurrent states segment by segment, orchestrate the two with a prefix tree and interval index, and combine them with tiered GPU memory, host memory, and remote storage.
