Hybrid Architecture KV Cache Optimization: 3x Prefill Throughput with Addressable State Replay

    This article explains why prefix caching becomes harder in hybrid architectures that combine full attention with linear or state space layers, where recurrent state cannot be sliced like KV cache. It presents an engineering approach built on layered cache descriptors, periodic state checkpoints, cost-aware prefix matching, and unified paging, plus tiered and cross-node reuse strategies. The approach delivers roughly 3x prefill throughput and nearly 90% lower p90 time-to-first-token on real coding agent traces, along with applicability limits and a practical rollout checklist.

    1. Background: Hybrid Architectures Are Mainstream, but Cache Management Is the New Bottleneck

    Over the past two years, linear attention and state space layers have shifted from experimental components to standard building blocks in open source LLM designs. Gated delta-style linear updates and state space recurrence layers are stacked alternately with full attention layers, forming a hybrid “full attention + linear layers” architecture. The motivation is clear: full attention layers provide precise global retrieval, while linear layers carry long-range information in a constant-size state, yielding lower per-step decode cost and a smaller cache footprint.

    The problem surfaces when the workload shifts from single-turn Q&A to scenarios like coding agents. A typical coding tool reads multiple files, repeatedly searches the codebase, makes multiple tool calls, and continuously accumulates and trims context. This produces two characteristics: highly repeated prefixes, where the same system prompt, repository context, and tool definitions are submitted over and over; and large, fast-growing context, where a single session easily reaches tens or even hundreds of thousands of tokens.

    In a pure attention architecture, prefix caching semantics are relatively clear: the cached objects are key-value pairs, and a hit skips redundant computation. In a hybrid architecture, the cached objects become two things with completely different semantics: the attention layers’ KV cache, and the “recurrent state” of the linear/state space layers. The latter is not indexed by token; it compresses the entire history into a fixed-size state tensor. This breaks the assumptions of traditional prefix caching: state cannot be arbitrarily truncated and reused by prefix length like KV pairs, and state updates are strongly order-dependent.

    2. The Core Conflict: Why Prefix Reuse Is Harder in Hybrid Architectures

    To see where the optimization headroom is, break the conflict apart.

    First, state cannot be sliced arbitrarily. KV cache is addressable: a hit on the first N tokens means fetching the cached first N tokens directly. Recurrent state is path-dependent: the state at step N is accumulated from the previous N-1 steps. If the cache only holds a state of length M (M < N), you cannot resume directly and must replay the inputs after M.

    Second, the two cache types have different capacity and eviction characteristics. KV cache grows linearly with length and suits paged management with block-level eviction. State cache is roughly constant in size but updated frequently and reused at a coarse granularity. Managing both with one eviction policy tends to cause imbalance, where state is evicted too early while KV blocks fill up GPU memory.

    Third, scheduling and batching semantics conflict. Continuous batching usually assumes requests can be inserted and removed freely at token boundaries, but stateful requests incur extra replay cost on resume. A scheduler unaware of this cost makes suboptimal decisions and causes head-of-line blocking.

    Fourth, the transfer cost structure of tiered storage differs. Offloading KV blocks to CPU or remote storage is routine, but state objects are small and updated densely. Moving them at block granularity amplifies the share of metadata and transfer overhead.

    3. Design Approach: Unify Both Cache Types Under an “Addressable + Replayable” Framework

    A practical engineering pattern for these conflicts is to stop treating state as an indivisible black box: build an addressable cache abstraction for hybrid state and make the scheduler explicitly aware of replay cost. Four points summarize it.

    1) Layered cache descriptors. Maintain a descriptor per request that records the block table for the attention part (which blocks are cached and on which storage tier) and the checkpoint sequence for the state part (at which token positions state snapshots were taken). A sketch of the structure:

    1. class HybridCacheDesc:
    2. block_table: dict[int, StorageTier] # attention KV blocks -> storage tier
    3. state_checkpoints: list[Checkpoint] # state snapshots: (token_pos, tier, ref)
    4. replay_cost_hint: int # estimated number of missing tokens

    2) State checkpoints instead of a single state point. Periodically persist state snapshots at several positions in long sequences, turning reuse from “all or nothing” into “nearest hit + bounded replay.” Checkpoint spacing is a tunable parameter: smaller spacing raises the hit rate but increases storage and write amplification; larger spacing raises replay cost.

    3) Cost-aware prefix matching. During matching, compute both the KV block hit length and the nearest state checkpoint position, take the larger “reusable length,” and use the number of replay tokens as a negative factor in scheduling priority, so high-replay-cost requests are not placed at the head of the queue.

    4) Unified block and page-aligned management. Manage KV blocks at a fixed page size and align state checkpoints to page boundaries by token position, so both object types share the same reference counting and eviction logic, reducing fragmentation and metadata bloat.

    4. Tiered Caching and Distributed Reuse

    In real deployments, GPU memory is only the first tier. A sensible hierarchy is GPU memory → host memory → remote cache/object storage. For hybrid state, the key is differentiated transfer strategy: KV blocks suit large-batch, block-granularity swap-in and swap-out; state checkpoints are small and numerous, so they suit batch packing and asynchronous prefetch, coordinated one step ahead with request scheduling to hide load latency behind computation.

    Cross-node reuse is especially valuable in coding agent scenarios: the same repository context is reused across multiple sessions and replicas. Placing state checkpoints together with KV blocks in a shared cache layer lets a new request resume from the nearest checkpoint instead of replaying the entire repository context from scratch. Three things need engineering attention: a globally consistent cache key design (usually determined jointly by model identifier, weight version, and prefix content hash, where a weight version change must invalidate old cache); reference counting and lease mechanisms to avoid evicting objects being read; and asynchronous write-back with failure fallback, so the system can fall back to a pure replay path when the cache is unavailable.

    5. Results Attribution and Applicability Boundaries

    In experiments replaying real coding tool call traces on high-end GPUs, this redesign raises prefill throughput to roughly 3x the original approach and cuts p90 time-to-first-token by nearly 90%; the gains hold after attaching a host memory cache of hundreds of GiB. The gains come from three sources: repeated prefixes are truly skipped rather than partially skipped; state checkpoints sharply reduce the cold-start cost of long-context requests; and the scheduler is no longer blocked by high-replay-cost requests, improving batching efficiency.

    The boundaries matter too: for single-turn short requests with no repeated prefix, gains are limited; checkpoint write amplification can become a new bottleneck under high-concurrency writes; and cross-node reuse depends on network bandwidth and consistent cache key design, where poor configuration adds extra latency. So before rollout, run replay evaluation on real traces, focusing on four metrics: cache hit rate, replay token distribution, state checkpoint overhead, and p90/p99 latency.

    6. Implementation Checklist

    • Quantify the workload first: measure prefix repetition rate, context length distribution, and session turns to decide whether state checkpoints are worth introducing.
    • Start small: treat checkpoint spacing, page size, and tier capacities as a group of tunable parameters and run a grid search.
    • Make the scheduler cost-aware: factor replay token count into ordering and admission control.
    • Improve observability: monitor hit rates, swap-in/swap-out bandwidth, and eviction reasons separately for KV blocks and state objects.
    • Design a fallback path: automatically fall back when the remote cache is unavailable to keep tail latency under control.
    • If running on a container platform or object storage, prefer general-purpose storage classes that support high-throughput sequential reads and writes, and integrate them with the monitoring and alerting system.

    The decode efficiency gains from hybrid architectures are real, but the prefill-stage benefits are fully unlocked only when state is designed as a first-class cache object.