RadixAttention Explained: KV-Cache Reuse and Inference Cost on GPU Clusters

RadixAttention keeps KV cache in a radix tree so shared prompt prefixes are computed once. Which workloads gain, what memory costs, and how to estimate it.

RadixAttention Explained: KV-Cache Reuse and Inference Cost on GPU Clusters
Written by TechnoLynx Published on 11 Jul 2026

RadixAttention is the KV-cache reuse technique in the SGLang serving runtime. Instead of discarding a request’s key and value tensors when the request finishes, it keeps them in a radix tree keyed by token sequences, so a later request that starts with the same tokens skips recomputing that prefix. In practice, few-shot examples, self-consistency questions, multi-turn chat histories and tree-of-thought search histories become shareable instead of fresh prefill work. How much it helps depends on two properties of your traffic: how much of it shares a leading prefix, and whether prefill or decode dominates your request time.

What Is the KV Cache, and Why Does Recomputing Shared Prompt Prefixes Waste GPU Time?

During inference, every attention layer produces key and value tensors for each token, and the KV cache stores them so the model can decode the next token without reprocessing the whole context. These tensors depend only on the tokens that came before them. So two requests that open with the same system prompt produce identical KV tensors for that stretch of tokens.

In the inference engines the SGLang paper describes, the cache is discarded when a request completes, so the next request with the same opening cannot reuse it. That waste shows up twice. Compute goes on producing tensors that already existed a moment ago, and memory is wasted holding them. NVIDIA’s TensorRT-LLM team notes that KV cache size grows linearly with model size, the number of batched requests and context length.

Before counting on gains from prefix reuse, measure whether your traffic actually shares prefixes.

Inside the Radix Tree: Matching, Storing and Splitting Prompts

A radix tree is a compressed trie: its edges carry sequences of tokens of varying length rather than one element each, which makes it space-efficient. In SGLang, the tree maps token sequences (the keys) to their KV tensors (the values), and those tensors live in GPU memory in a paged layout where each page holds one token. The tree itself sits on the CPU, and the authors describe its maintenance overhead as small. RadixAttention is also compatible with continuous batching and paged attention.

Each request goes through three operations. On arrival, the runtime searches the tree for the longest cached token sequence that matches the start of the prompt. It loads those KV states and runs prefill only for the tokens that remain. When the request finishes, its prompt and generated tokens are kept in the tree rather than freed. When memory runs short, nodes are evicted. A new prompt that branches off partway along an existing edge splits that edge into a shared node and two children, and that split is how the tree comes to represent shared and divergent parts of many prompts.

Worked Example: Three Requests and One System Prompt

Assume a chat service where every request begins with the same system prompt S. (These are assumptions for illustration, not measurements.)

  1. A arrives with an empty tree. The engine prefills S and Q1 in full and stores the path root → S → Q1.
  2. B arrives. S matches, so only Q2 is prefilled, and the tree branches at the end of S into Q1 and Q2.
  3. C arrives. S matches again, and F and Q3 are prefilled and hung under S as a third branch.
  4. If a later request repeats S and F before asking Q4, it hits two levels at once and prefills only Q4. The SGLang paper reports exactly this two-level sharing on HellaSwag, where few-shot examples and a common question prefix are both reused.

The prefill saved is the matched path, and nobody had to mark S or F as cacheable.

How Does the Radix Tree Structure Enable Automatic Prefix Reuse Across Requests?

The reuse is automatic because the runtime matches every incoming prompt against the tree and needs no hints from the application. The tree shape also handles irregular tree-structured sharing beyond basic prefix sharing. SGLang’s fork primitive and chained generation calls create tree-structured sharing, with many branches growing from one state, and the radix tree represents those branches directly.

What the Tree Keeps and What It Evicts

SGLang uses LRU eviction that removes the least recently used leaf first, so shared ancestors stay reusable until they become leaves themselves. A shared system prompt near the root therefore stays cached until every branch below it has been evicted. Nodes used by the batch that is currently running cannot be evicted. Each node carries a reference counter for the running requests that use it, and a node is evictable only when its count reaches zero.

The SGLang paper describes no fixed cache pool: cached tokens and running requests share one memory pool, and when enough requests are waiting, the system evicts every cached token in favour of a larger batch. That design choice matters for the trade-offs discussed below.

Why Request Order Changes the Hit Rate

The SGLang paper defines cache hit rate as cached prompt tokens divided by total prompt tokens, and it points out that a scheduler that keeps switching between unrelated requests thrashes the cache. For a fixed batch, processing requests in longest-shared-prefix-first order (equivalent to a depth-first walk of the tree) gives the optimal hit rate, provided the cache holds at least the longest request. On the authors’ benchmarks, cache-aware scheduling reached 96% of the optimal hit rate on average.

Under a live stream of queries, results depend on the order in which queries are processed. A 2025 scheduling study found that first-come-first-served wins at low request rates while longest-prefix-match wins at higher rates. The same study proposes a hybrid that takes a few greedy prefix-match steps and then serves the oldest waiting query, which avoids starving requests that never share much with the rest. It also shows that deciding whether a time-to-first-token (TTFT) target can be met for a query stream under RadixAttention is NP-hard.

What Is the Difference Between RadixAttention and a Standard Per-Request KV Cache?

A standard per-request KV cache lives only as long as its request: it serves decoding within that request and is then discarded. RadixAttention makes the cache persist across requests and treats it like a conventional cache with lookup, insertion and eviction.

Approach Cache lifetime How a prefix is matched Eviction
Per-request KV cache Freed when the request ends No cross-request matching Not applicable
vLLM automatic prefix caching Blocks persist after the request finishes Each block is hashed on its own tokens plus all prefix tokens before it LRU free queue; a finished request’s last block is evicted first
SGLang RadixAttention Prompt and output tokens retained in the tree Radix tree walk at one-token page granularity LRU leaf-first, with reference counters protecting running requests
TensorRT-LLM block reuse Filled blocks are stored in a radix search tree Tree search when a request is added; partial block reuse supported Prioritised LRU with priorities from 0 to 100, plus optional offload to host memory

The SGLang authors claim RadixAttention was the first design to treat the KV cache as a tree-based LRU cache with multi-level sharing and cache-aware scheduling. The vLLM documentation, for its part, calls prefix caching “almost a free lunch” that leaves model outputs unchanged, and lists SGLang among the frameworks that use it. SGLang’s HiCache documentation notes that larger pages reduce metadata overhead but can lower the hit rate when only part of a page matches, so long common prefixes favour larger pages and diverse prefixes favour smaller ones. All three engines reuse cached KV blocks across requests that share a prefix, so if you already run one of them, we would not switch engines for the data structure alone.

TensorRT-LLM’s cache salting restricts reuse to requests carrying the same salt value, which guards against prompt-theft attacks between users but also limits sharing to within each salt group.

Which Workloads Gain from RadixAttention, and Which See Little

The gain is largest for long-prompt, short-output requests where prefill dominates the time, and smallest where decoding dominates. A 2025 scheduling analysis states the condition: RadixAttention gives significant gains only when the total edge length of the radix tree built from the query stream is significantly less than the sum of the prompt lengths.

Workload Why it does or does not share Expected gain
Few-shot evaluation and prompting Identical examples lead every prompt High: less prefill and a larger batch
Multi-turn chat Each turn extends the previous history High in prefill; SGLang measured 1.7× lower average first-token latency on Vicuna-33B in production
Agents Input-to-output token ratios of 100:1 in some cases, per Modular’s handbook High, because reprocessing the prompt is most of the cost
Self-consistency, tree-of-thought, forked calls Many branches from one state High; higher hit rate gave larger batches and higher throughput on tree-of-thought
RAG pipelines Repeated prompt structures Useful, per Modular’s handbook
Long-output chat sessions Little sharing between sessions, and decode dominates Almost none
Shared content at non-leading positions Prefix matching gives no benefit there None from prefix caching; chunk-level reuse is a different technique
Hybrid attention plus recurrent (state-space) models In-place recurrent state allows exact-match hits only Limited without specialised admission and eviction

The production numbers in the SGLang paper show the range. After one month of serving, the authors observed a 52.4% hit rate for LLaVA-Next-34B and 74.1% for Vicuna-33B, with hits coming from common system messages, reused example images and multi-turn histories. On their benchmarks, hit rates ran from 50% to 99%. A 2025 trace study at a large cloud provider found that reuse is skewed across requests, that single-turn reuse matters as much as multi-turn, and that reuse patterns are predictable within a request category even though they vary widely overall.

On a ShareGPT benchmark with no reuse opportunities, managing the tree took 0.2 seconds out of 74.3 seconds, an overhead under 0.3%. That result is why SGLang turns RadixAttention on by default.

The non-leading case deserves a closer look, because it is where prefix caching runs out. KVBoost, a 2026 research system, caches fixed-size chunks so that shared text can be reused at any position in the prompt. On a bug-localisation workload with Qwen2.5-3B, it reported a 4.49× mean TTFT speedup over full recomputation and was 16% faster than vLLM prefix caching. It pays for this with seam-repair recomputation at chunk boundaries. Where prompts have a true leading prefix, plain prefix caching avoids that extra cost.

Memory and Eviction: What Keeping Prefixes Costs

Cached prefixes and the KV state of active requests compete for the same GPU memory, so aggressive caching can reduce concurrency and create queueing hotspots. A 2026 queueing analysis of prefix caching on wireless edge GPUs found that TTFT can be non-monotonic in cached-prefix depth for exactly this reason, and that adding persistent caching can increase latency by reducing concurrency. The paper’s design handles part of this by giving cached tokens up to the batch when demand rises. But that also means every cached token is evicted once enough requests are waiting.

Capacity is the second limit. The SGLang team wrote in September 2025 that as contexts grow and conversations add more rounds, the hit rate declines because most historical KV caches have to be evicted to make room. Their answer was HiCache, a hierarchical caching design, which treats GPU memory as L1, host memory as L2 and distributed storage as L3, tracked by a HiRadixTree that records which tier holds each span. In a coding-agent deployment with Qwen3-Coder-480B and dialogues past 25K tokens, adding HiCache with a 3FS backend raised the hit rate from 40% to 80%, cut average TTFT by 56% and doubled throughput. The documentation also warns that hit rate does not grow linearly with cache size: once the hot tokens are cached, more capacity adds little.

In HiCache, host memory (L2) is private to each inference instance, so one instance’s KV cache becomes visible to another only once it reaches L3. Cross-instance reuse therefore goes through L3 distributed storage.

Eviction policy is the third lever, and plain LRU is not the end of it:

  • TensorRT-LLM’s priority-based eviction lets a deployer pin a system prompt or latency-critical blocks. NVIDIA reports this raised hit rates by around 20% in internal benchmarks, which is a vendor figure rather than an independent test.
  • KVBoost scores chunks by an importance proxy and uses LRU as a tiebreaker, and its authors report this beats pure LRU where some content, such as system prompts, matters more than the rest.
  • Marconi, presented at MLSys 2025, admits and evicts entries by forecast reuse and by compute saved relative to memory footprint. It reported up to 34.4× higher token hit rates on hybrid models.

How Does Prefix Cache Reuse Translate into Throughput and Inference Cost on a Fixed GPU Footprint?

Prefix reuse lowers cost through two separate mechanisms, compute and memory. The first is compute: cached prompt tokens skip prefill, which reduces prefill time and first-token latency. The second is memory: shared KV tensors use less memory, which allows a larger batch and higher maximum throughput. The SGLang tree-of-thought experiment shows both at once, with a higher hit rate giving a larger batch, higher throughput and lower latency.

On a fixed GPU footprint, cost per token is GPU-hours divided by tokens served, so anything that raises served throughput on the same hardware lowers it. The compute saving is limited to prefill, because reuse mostly shortens prefill time. If decode dominates, there is almost no speedup, as SGLang’s long-output chat results show. The delta that matters is GPU-hours saved per million requests on the real request mix, not a hit rate on its own. The wider question of utilisation and the memory-bound decode ceiling belongs in what GPU throughput means for cluster sizing. Converting saved prefill into a bill, including how hosted APIs price cache hits, is covered in how token pricing and caching change the bill.

Across several replicas, cache-aware routing raises the hit rate. Each SGLang worker keeps its own tree, and a router holds a meta-tree to send requests to the worker with the best prefix affinity. SGLang v0.4’s cache-aware load balancer reported throughput rising from 82,665 to 158,596 tokens per second and the hit rate from 20% to 75%. That benchmark used multiple long, perfectly balanced prefix groups, so treat it as an upper case rather than an expectation. The CPU is also part of the cost. LMSYS notes that an unoptimised engine can spend as much as half its time on CPU work such as scheduling and prefix matching, and SGLang hides the radix-cache operations by preparing the next batch while the GPU runs the current one.

How Do I Estimate the Throughput Gain from Prefix Caching Before Adopting It in My Serving Stack?

Estimate it from your own traffic before you change engines or sizing, because the gain is a property of the workload, not of the feature. A procedure we would follow:

  1. Capture a representative trace. Record real prompts tokenised as in production, since matching runs on exact token sequences from the start.
  2. Compute the ideal hit rate offline. Build the radix tree from the trace and compare its total edge length with the sum of prompt lengths. One minus that ratio is the best hit rate any scheduler could reach.
  3. Profile the prefill and decode split. Prefix reuse cuts prefill time, so the gain depends on prefill’s share of request time.
  4. Bound the gain. Reuse mostly shortens the prefill part, so a small prefill share caps the gain whatever the hit rate.
  5. Check the memory budget. Measure KV bytes per token on the actual model, precision and engine rather than deriving it from layer dimensions, because block allocation and metadata add overhead. Then see how many cached tokens fit beside your target batch. The 2025 cloud trace study found that the cache size needed for an ideal hit ratio is moderate, but that is their workload, not yours.
  6. Replay at your real request rate. Run with caching on and off, and with FCFS and prefix-match scheduling, because which order wins depends on load.
  7. Judge on more than hit ratio. The 2026 edge-caching analysis argues that results come from several interacting mechanisms (computation reuse, cache-affinity hotspots and lost concurrency), not from hit rate alone.

The general method behind steps 3 and 6 is in our guide to profiling GPU kernels to find the real bottleneck: the limiting resource is whichever one saturates first, and the right fix depends on which resource that is. TechnoLynx does this kind of profiling as part of its GPU performance engineering work, making workloads faster and cheaper on the target hardware.

When the Cache, Not the GPU Count, Sets the Ceiling

RadixAttention added under 0.3% overhead on a benchmark with nothing to hit, which is why SGLang turns it on by default. The hard decisions start once the cache fills up: how much memory to give persistent prefixes instead of concurrent requests, whether to tier into host memory or remote storage, and how to route across replicas without creating hotspots. The scheduling problem is formally hard, and the researchers who formalised it note a lack of empirical benchmarks for comparing strategies. A team that measures its own prefix overlap and prefill share can at least tell whether its next spend should go on GPUs, on host memory for a cache tier, or on the interconnect that lets replicas share what they have already computed, a choice weighed in DAC vs AOC for GPU cluster links.