Hybrid Architecture KV Cache Redesign: Analyzing Prefill Throughput Gains
This article examines why hybrid architectures that interleave full attention and linear layers have become a common choice for long-context agent workloads, and why their prefix caching is fundamentally harder than in pure attention models. It explains the core bottleneck: state is split into position-indexed KV blocks and fixed-size recurrent states with completely different lifecycles, causing granularity mismatch, snapshot overhead, and unsynchronized eviction. The article then presents four design principles—unified addressing with joint eviction, non-uniform state checkpoints, replay and state backfill scheduling, and tiered storage with cross-node reuse—along with practical guidance on measurement, capacity planning, prefix normalization, and cache warmup. Readers will learn how treating fixed-size state as a first-class cache object can compress the replay range and turn compute savings into prefill throughput and lower p90 time-to-first-token.
1. Background: Why Hybrid Architectures Are Becoming the Default for Long-Context Workloads
In model design over the past two years, the interleaved stacking of “full attention layers + linear layers” has been shifting from an experimental approach to a mainstream configuration. Linear layers—including various linear attention variants, gated linear units, and state space structures—compress historical information between tokens into a fixed-size recurrent state that no longer grows linearly with sequence length. Full attention layers, meanwhile, preserve exact token-by-token retrieval. Interleaving the two in a fixed ratio gives a model both near-constant decoding state overhead and controllable long-range accuracy loss.
This tradeoff is especially attractive for AI agent workloads. A single task in an agentic coding tool often involves dozens of rounds of tool calls, and each round must reassemble the system prompt, repository snippets, historical diffs, and error logs into the context. Prefixes can easily reach tens of thousands to hundreds of thousands of tokens. What actually slows down the experience here is not decoding speed, but the fact that nearly identical prefixes must be recomputed on every request.
2. The Real Bottleneck: Prefix Caching Goes from One Cache to Two
Prefix caching semantics in pure attention models are clean: each position maps to a set of Key/Value tensors, which are split into blocks, indexed by hash, and skipped entirely on a cache hit.
Hybrid architectures complicate this because state is split into two categories with completely different lifecycles:
- Attention state (KV): corresponds one-to-one with positions, can be chunked at any granularity, partially hit on demand, and concatenated across requests.
- Linear state (recurrent state): a fixed-size tensor independent of sequence position, semantically equivalent to “the model’s memory after reading the first n tokens.” It cannot be chunked; it either exists as a whole at a given position or does not exist at all.
This creates three engineering problems. First is granularity mismatch: a 60% block-level KV hit rate does not mean the linear state is usable. If the cache holds no state snapshot corresponding exactly to the hit boundary, the system must replay all subsequent tokens from the nearest state point, which largely erodes the benefit. Second is snapshot cost: frequently persisting fixed-size states to increase the number of hittable boundaries introduces additional memory footprint, memory bandwidth consumption, and serialization overhead. Third is unsynchronized eviction: if the two caches use independent eviction policies, fragmentation quickly appears where “the KV is still there but the state has been evicted,” structurally lowering the hit rate.
3. Design Principles: Treat State as a First-Class Cache Object
Optimization directions validated in real agent trajectory replays can be abstracted into four mutually supporting principles.
3.1 Unified Addressing and Joint Eviction
Maintain a composite key for each prefix block that indexes both the KV block and the “state snapshot at the block’s end position,” and admit, reference-count, and evict the two as a single indivisible unit. Illustrative logic:
class HybridCacheEntry:prefix_hash: bytes # Hash of prefix content, used as composite keykv_blocks: list[Block] # Attention cache organized by blocksstate_snapshot: Tensor # Fixed-size linear state aligned with kv_blocks boundariesref_count: intlast_access: intdef lookup(cache, prefix_hash):e = cache.get(prefix_hash)if e is None or e.state_snapshot is None:return None # Treat as a full miss if state is missing, avoiding partial hitscache.touch(e)return e
3.2 Non-Uniform State Checkpoints
There is no need to save state at every block boundary. Checkpoints can be selected by “hotness + position”: sample densely in high-reuse regions such as system prompts, repository skeletons, and long-lived tool definitions, and sample sparsely near the tail of a session. This trades limited state storage for a higher density of effective hit boundaries.
3.3 Coordinating Replay and State Backfill Scheduling
On a miss, the scheduler should prioritize the replay length that “lets the most subsequent requests hit,” rather than simply taking the longest reusable prefix. State produced by replay should enter the memory tier before being written back to the cache, avoiding synchronous disk writes that block the current batch.
3.4 Tiered Storage and Cross-Node Reuse
Keep the hottest states and KV in GPU memory, use host memory as the second tier, and remote distributed storage as the third tier. Cross-node reuse requires prefix hashes to be consistent across the cluster, and accepts the intermediate benefit of “remote hit but still needing to replay locally.”
4. Where the Gains Come From
In public experiments replaying real agent trajectories on a single GPU, this class of solution raised prefill throughput to roughly three times that of a baseline inference framework, and cut p90 time-to-first-token by nearly 90%. After adding a host memory cache on the order of hundreds of GiB, long-tail requests still retained their gains. The causal chain is not mysterious: prefill compute is proportional to the number of missed tokens, and state snapshots compress the range that “must be replayed” from the entire prefix down to a few boundary gaps, so compute savings translate directly into throughput. The long tail of time-to-first-token comes mainly from recomputation of a few extremely long contexts, so improvements in hit rate help p90/p99 far more than the mean.
5. Implementation Recommendations
- Measure before optimizing: separately track KV hit rate, state hit rate, and the replay token distribution to determine whether the problem is granularity or capacity.
- Plan capacity based on “state bytes × number of checkpoints,” not KV alone; fixed-size states are often the more expensive item under long contexts.
- Prefix normalization (stable ordering of tool definitions, fixed system prompt position) can significantly improve hash hit rates and is a zero-cost gain.
- Make cache warmup and asynchronous backfill background tasks, with monitoring and alerting to watch for regressions in hit rate and replay duration.
- For cloud deployments, container platforms can orchestrate inference services, high-performance block or object storage can carry the third cache tier, and monitoring and alerting systems can track TTFT percentiles. General capabilities from Baidu AI Cloud can serve as a reference path for capacity and observability work.
The benefits of hybrid architectures are not automatic; they depend on whether the cache system is redesigned around a two-tier first-class model of “attention blocks + fixed-size state.” Only when state management is done correctly does the prefill cost of long-context agent workloads truly become controllable.
