Redesigning Cache for Hybrid Architectures: Key Practices to Accelerate Prefill
This article explains why caching becomes the main bottleneck in hybrid architectures that interleave full attention and linear layers, especially for long-context, multi-turn workloads such as AI coding tools. It contrasts key-value cache with recurrent state cache, outlines how naive implementations degrade, and presents five design principles: unified addressing, block-level incremental prefill, copy-on-write with reference counting, tiered GPU/host/remote caching, and consistency-aware eviction. It also breaks down latency and throughput gains and offers practical rollout advice.
1. Background: Hybrid Architectures Are Mainstream, but Cache Becomes the New Bottleneck
Recent open-source LLM designs increasingly interleave full attention layers with linear attention and state space layers—such as gated delta state updates and selective state compression—forming a hybrid “full attention + linear layers” structure. This structure delivers two core benefits: lower compute and memory access per decoding step, and cache usage that no longer grows linearly with context length.
However, workloads like AI coding tools differ sharply from chat scenarios. System prompts, repository context, tool definitions, multi-turn patches, and reasoning traces are carried repeatedly. A single request can easily reach tens of thousands to hundreds of thousands of tokens, and adjacent requests share large common prefixes. In this setting, cache management for hybrid architectures becomes significantly more complex and turns into the primary cost source during prefill.
2. The Fundamental Difference Between the Two Cache Types
Understanding the optimization space requires clarifying the semantics of the two state types.
- Key-value cache: Full attention layers retain keys and values for every historical token. It can be trimmed, concatenated, and discarded at token granularity and naturally supports prefix sharing.
- State cache: Linear layers maintain a fixed-size recurrent state that “compresses” the entire history into a matrix or vector. The state is path-dependent, and the contribution of a specific token cannot be recovered from it.
This leads to three direct consequences. First, states cannot be sliced arbitrarily; any insertion, deletion, or rollback invalidates all subsequent states. Second, when reusing a common prefix, you must reuse not only the key-value blocks but also the corresponding state snapshots. Third, multi-branch scenarios—such as exploring multiple fix candidates in parallel under the same prefix—require state forking and copy-on-write.
3. Why Naive Implementations Degrade
Many inference frameworks treat hybrid models as “several pure attention layers plus several special layers” for compatibility. In engineering practice, this usually degrades into the following strategies, each with clear costs:
- No prefix reuse: Every request is prefilled from scratch, long common prefixes are recomputed, and throughput drops sharply as context length grows.
- Reusing key-value only, not state: Hybrid layers still need recomputation, and state and key-value are misaligned along the timeline, raising correctness concerns.
- Discard and recompute the whole segment: In branching or editing scenarios, local updates are impossible and only full rollback is available.
- Cache granularity mismatched with memory pages: State snapshots are small with special alignment requirements, easily producing substantial internal fragmentation and low GPU memory utilization.
4. Five Key Points for Redesigning the Cache
A practical solution typically includes the following elements. They are coupled and require holistic design rather than local patches.
4.1 Unified Addressing: Treat State as a First-Class Citizen in a Paged Cache
Establish a unified logical address space for key-value blocks and state snapshots, using a composite key of “prefix fingerprint + layer range + block index.” Store state snapshots with fixed byte alignment to avoid fragmentation from mixing them with key-value blocks.
key = hash(prefix_fingerprint, layer_range, block_index)entry = { kv_blocks[], state_snapshot, ref_count, last_access }
4.2 Block-Level Incremental Progress: Schedule by Reusable Boundaries, Not Tokens
Advance prefill block by block and persist a state snapshot after each completed block, so reuse boundaries align with scheduling boundaries. Block size must balance snapshot overhead against reuse hit rate: too small increases metadata and copy costs, while too large reduces reuse granularity for branching scenarios.
4.3 Branch-Friendly: Copy-on-Write and Reference Counting
When multiple candidates are explored in parallel, use copy-on-write for the state corresponding to the shared prefix and allocate new state only after the fork point. Combined with reference counting for timely reclamation, this prevents long-tail requests from filling GPU memory.
4.4 Tiered Cache: Coordinating GPU Memory, Host Memory, and Remote Storage
Keep hot data in GPU memory, move warm data to a large host-memory cache pool, and place cold data in distributed or object storage. The key to tiering is “consistent addressability”: all three tiers use the same composite key, and migration changes only location, not identity, enabling cross-node reuse of the same prefix state.
4.5 Consistency and Eviction: Distinguish Reusable from Non-Reusable
Introduce checksums and version numbers for state snapshots, invalidating them entirely when model weights or configurations change. Eviction should not rely only on last access time; it should also consider “branch fan-out” (how many active branches reference it) and “rebuild cost” (the compute needed to recompute the prefix).
5. Where the Gains Come From: A Breakdown of Latency and Throughput
Prefill time can be roughly decomposed into a compute term and a memory-access term. When prefix reuse fails in hybrid architectures, the compute term is amplified by repeated computation, while moving and poorly aligned state snapshots amplify the memory-access term. The designs above suppress both: block-level reuse cuts repeated compute, unified addressing and alignment reduce ineffective data movement, and tiered caching expands the hit range from a single GPU to a cluster.
In public technical discussions, replaying real AI coding traces on high-end accelerator cards has shown prefill throughput improvements on the order of several times, with p90 time-to-first-token dropping by more than 80%. The gains persist even with host-memory caching at the hundreds-of-gigabytes level, and cross-node state reuse is already supported. Note that the exact multipliers depend heavily on the model’s layer mix, context length distribution, and branch count; engineering evaluation should rely on replaying your own traces.
6. Engineering Recommendations
- Profile traces first: Measure the distribution of common prefix lengths, branch fan-out, and average and p90 context lengths before deciding block size and the capacity ratio across three tiers.
- Ensure observability: Build metrics and logs for cache hit rate, state snapshot movement, and eviction reasons, with monitoring and alerts to locate jitter.
- Canary and rollback: Use dual switches—“reuse on/off” plus “prefix fingerprint version”—for canary rollout, and quickly fall back to full prefill if accuracy or latency anomalies appear.
- Capacity elasticity: Pair stateless inference instances with container-platform autoscaling, and deploy the cache pool independently to adjust the GPU-to-host-memory ratio by workload.
7. Conclusion
The benefits of hybrid architectures do not automatically propagate to the serving layer. Elevating state cache to a first-class, addressable, paged, and migratable object on par with key-value cache—and rebuilding scheduling around block-level reuse, copy-on-write, and tiered media—is the key to accelerating prefill under long-context, multi-turn workloads. For enterprises building AI coding assistants or long-document analysis capabilities, this methodology maps directly into a checklist for capacity planning and performance acceptance.
