Hybrid Architecture Cache Redesign: A Deep Dive into Prefill Throughput Gains
This article explains why agent workloads push the prefill stage into the bottleneck and how to redesign state caching for hybrid architectures that combine full attention layers with linear layers. It covers the two distinct state types and their lifecycles, a block-based cache structure with prefix hashing and partial hits, a pipelined prefill execution model with compute and data movement overlap, and practical pitfalls around hashing, state drift, isolation, observability, and capacity elasticity.
1. Problem Background: Agent Workloads Push Prefill to the Bottleneck
Over the past year, several model families in the industry have shifted toward hybrid architectures that combine full attention layers with linear layers. The motivation is straightforward: full attention layers handle precise global information retrieval, while linear layers (such as state space or linear recurrence structures) carry long-range history with constant-size state. This reduces per-step computation during decoding and significantly shrinks the memory footprint of the state cache.
Architectural gains do not automatically carry over to the serving side. Agent workloads have three distinct characteristics that concentrate pressure on the prefill stage:
- Very long contexts: system prompts, tool definitions, interaction traces, and retrieved snippets stack up, so a single request easily reaches tens of thousands to hundreds of thousands of input tokens.
- Highly repetitive prefixes: multiple turns in the same session share large identical prefixes, with templates and tool descriptions changing very little.
- Bursty and heterogeneous requests: many concurrent sessions, long-tailed input length distributions, and batch windows that are hard to keep stable.
Prefill must process all input tokens at once. It is compute-intensive and highly parallel, and it is the main contributor to time to first token (TTFT). When input length keeps growing and decoding-side optimizations are already near their limits, prefill naturally becomes the new system bottleneck. The key engineering question is therefore how to redesign the state cache for hybrid architectures so that prefill computation and data movement are reused and overlapped.
2. State Forms in Hybrid Architectures: Two State Types, Two Lifecycles
Optimizing the cache first requires recognizing that “state” in a hybrid architecture is not one thing but two kinds of data with very different properties:
- Attention-side state: grows with the number of layers and attention heads, has a shape tied to sequence length, and is position-addressable. It suits prefix-level reuse and paged management.
- Linear-layer-side state: usually a fixed-size recurrent state, independent of sequence length. It is a cumulative quantity that evolves in order, and once advanced it cannot roll back to an intermediate point.
This difference leads to a conclusion that is easy to overlook: linear-layer state has no native random access. If paging and reuse strategies designed only for attention caches are carried over unchanged, the linear-layer portion can only be recomputed in full, and the memory advantage of the hybrid architecture is cancelled out by computation cost during prefill. The design goal for a hybrid state cache should therefore be to describe, allocate, and reuse both state types within one unified scheduling framework.
3. Core Idea: Store the Cache by Block Instead of by Sequence
A common general approach in the industry is to split a long sequence into fixed-length chunks, maintain a reusable state snapshot for each chunk, and attach the necessary metadata. A schematic data structure looks like this:
class StateBlock:block_id: int # Block indexprefix_hash: int # Hash of the prefix content, used for hit detectionattn_state: Tensor # Attention-side state (position-addressable)linear_state: Tensor # Linear-layer recurrent state (fixed-size snapshot)ref_count: int # Reference count, supports sharing across requestsfilled_len: int # Filled length, supports partial hits
On top of this, cache management has to solve four problems:
- Hit detection: compare block by block using the prefix hash, allowing “first N blocks hit plus a partial tail hit” and avoiding all-or-nothing extremes.
- Unified allocation: allocate both state types from the same memory pool at block granularity to reduce fragmentation; the fixed-size linear-layer snapshots can stay resident, while attention state becomes the swappable layer.
- Sharing and isolation: read-only prefixes (system prompts, tool definitions) are shared by reference across sessions; session-private content uses copy-on-write to prevent cross-contamination.
- Eviction policy: combine reference counts with last-use time, evicting private blocks of long-tail sessions first and keeping high-reuse public blocks.
4. Prefill Execution Rework: Block Pipelines and Overlap
With a block-organized cache, prefill scheduling can change completely. The traditional implementation computes a request straight through; the improved general pattern is pipelined:
Request queue -> prefix hit lookup -> compute missed blocks (linear-layer recurrence + attention fill)-> write state blocks back to cache -> generate first token from the last block
Key optimizations include:
- Overlapping computation and data movement: while one block is being computed, asynchronously prefetch the cache needed by the next block, hiding memory bandwidth waits under computation.
- Cross-request batching: merge missed blocks from multiple requests into a unified batch to improve tensor parallelism efficiency and reduce idle batch windows caused by long-tailed inputs.
- Incremental advance instead of rollback: linear-layer state advances strictly in block order with no mid-way rollback; when branching is needed (for example, a tool call retry), fork from the nearest block snapshot rather than recomputing from the start of the sequence.
- Scheduling fairness and preemption: set block-level quotas for long-input requests so a single very long request cannot monopolize compute resources and cause TTFT jitter in other sessions.
The point of this rework is that prefill turns from an “indivisible black box” into an addressable, reusable, preemptible sequence of blocks, improving both cache hit rate and batching efficiency. This is the main source of the multi-fold prefill throughput gains. The exact multiple depends heavily on input length distribution, prefix repetition rate, and hardware configuration, so engineering decisions should be based on measured data from your own workload.
5. Implementation Notes and Common Pitfalls
- Match hashing and block length to the workload: blocks that are too small raise metadata and scheduling overhead, while blocks that are too large reduce the benefit of partial hits; values are usually chosen near natural boundaries such as tool descriptions and template sections.
- Watch for state drift: linear-layer recurrence is sensitive to numerical accumulation, and changes in blocking or batch order can introduce subtle differences, so consistency checks should run against an evaluation set.
- Isolation and compliance: shared prefixes must be genuinely user-independent public content; the lifecycle, encryption, and destruction policies for session data in the cache must be defined explicitly.
- Observability first: build monitoring and alerting for cache hit rate, block reuse distribution, prefill queue time, and memory usage, and use general-purpose logging and monitoring/alerting capabilities to accumulate metrics, so you can tell whether the optimization actually takes effect.
- Capacity elasticity: the state cache is essentially a trade of memory for compute, so it is better to adjust replicas and cache quotas by peak and trough using container platforms and elastic scaling than to plan capacity statically.
6. Conclusion
The decoding gains from hybrid architectures are only fully realized when the prefill stage receives equal attention. Restructuring the state cache into a unified system that is block-level, addressable, shareable, and pipelined, so that attention state and linear-layer state cooperate within one scheduling framework, is the general path to higher throughput for long-context agent workloads. For developers, the real lever is not any single technique but the combination of cache abstraction, scheduling pipelines, and an observability system.
