Radix Cache for LLM Inference: How Prefix Reuse Cuts GPU Work

How the SGLang radix cache reuses the longest shared prompt prefix to cut prefill work, when it pays, what breaks it, and how to check its hit rate.

Radix Cache for LLM Inference: How Prefix Reuse Cuts GPU Work
Written by TechnoLynx Published on 11 Jul 2026

The SGLang radix cache keeps the KV cache of finished requests in a radix tree keyed by token sequences. Before each prefill it finds the longest cached prefix of the incoming prompt, so only the tokens after the point of divergence have to be computed. Whether that cuts GPU work for you depends almost entirely on how much of your traffic opens with the same tokens.

TechnoLynx audits deployed LLM serving paths (caching, batching, routing and serving configuration) to find latency and cost gains before recommending model replacement, starting by profiling GPU performance on the deployed serving path.

SGLang Radix Cache Versus a Per-Request KV Cache

A conventional inference engine builds a KV cache for each request and discards it once that request finishes, so the next request with the same system prompt recomputes it from scratch. RadixAttention, the mechanism behind the SGLang radix cache, keeps those tensors after the request ends and manages them as a cache: matching, insertion and eviction all happen on a radix tree. Both prompts and generated outputs stay in the tree, which is why a multi-turn conversation can reuse its own previous answers on the next turn.

The reuse is valid because the KV cache for a token depends only on the tokens before it, so any two sequences with the same prefix produce identical KV entries for that prefix. A per-request cache discards that work when each request ends. A radix cache retains it for any later request that shares the prefix.

How SGLang Finds the Longest Shared Prefix

The radix tree maps token sequences (the keys) to their KV cache tensors (the values), and the tensors sit on the GPU in a paged layout where each page holds one token. A new request walks the tree from the root, consuming cached nodes for as long as its tokens match, and then computes fresh nodes for the divergent suffix.

The SGLang front end always sends complete prompts; the runtime does the prefix matching, reuse and caching on its own, and the tree structure itself lives on the CPU. That bookkeeping is cheap. In the SGLang paper’s test on ShareGPT with no reuse opportunities at all, managing the RadixAttention structures took 0.2 seconds of a 74.3-second run, under 0.3% overhead, which is why the authors enable it by default. SGLang v0.4 goes further and overlaps CPU scheduling with GPU computation so that radix cache operations are hidden behind the running batch.

The algorithm itself (why the tree is the right structure, and how it shows up in GPU utilisation) is covered in depth in RadixAttention explained: KV-cache reuse and GPU utilisation; this page stays on how the cache behaves under real traffic.

Token-Level Radix Tree Versus vLLM’s Block-Hashed Prefix Caching

vLLM’s automatic prefix caching also reuses KV for shared prefixes, with whole blocks as the unit. It hashes each KV block by the tokens in the block together with the hash of the parent block, plus extra values such as LoRA IDs or multimodal input hashes. A cache hit therefore needs a whole block to match: in the vLLM design documentation’s own example, a request sharing its first 10 tokens with an earlier one hits only the first two four-token blocks (8 tokens), because the third block matches just 2 of its 4 tokens.

Property SGLang radix cache vLLM automatic prefix caching
Unit of reuse Single tokens; partial overlaps detected at any boundary Whole blocks, --block-size default 16
Lookup Walk the radix tree from the root until tokens diverge Hash prompt blocks and look up cached blocks
Partial block at the end of a shared prefix Reused Missed: only whole matching blocks hit; the partial block is recomputed
Eviction order Least recently used leaf first Least recently used block at the head of the free queue

The practical difference is narrower than it sounds. Block hashing integrates cleanly with PagedAttention, and smaller blocks capture more partial overlaps at the price of more hash-table overhead. Token granularity matters most when shared prefixes end at arbitrary positions, for example when a request shares only 800 tokens of a 2,000-token system prompt. vLLM also offers a per-request cache_salt that is folded into the first block’s hash, so only requests with the same salt can share cached blocks in a multi-tenant deployment. We would not pick a serving framework on this one property; it is one input among many.

Which Workloads Gain from Prefix Reuse, and Which See Nothing

Prefix reuse pays when requests share opening tokens. SwiftCache (2026) measured prefix cache hit rates of 90.7% for multi-turn conversation and 81.8% for question answering, against 6.3% for summarisation and 0.1% for code completion, and noted that turning prefix caching off for the latter two would not significantly change performance.

Workload Where the shared prefix comes from What to expect
Multi-turn chat Every turn resends the whole history plus a short new input High hit rate; 90.7% in SwiftCache’s measurement
Agents and tool use System prompt, tool schema and growing history resent every turn High; Preble found 85% to 97% of prompt tokens shared across five workloads, including tool use and embodied agents
Few-shot templates Examples cached once for every query that uses them High; on HellaSwag SGLang shares both the examples and the question prefix
RAG and document QA Repeated retrievals or several questions about one document High when documents repeat
Unique one-shot prompts Nothing shared No hits, slight bookkeeping overhead
Long-output generation Decode time dominates total latency Almost no speedup

Prefill is the forward pass over all input tokens; decode then generates output tokens one at a time, each depending on the tokens before it. A radix cache shortens prefill, which is why its benefit shrinks when long outputs make decode dominate.

The summarisation figure needs one note. A 2025 scheduling paper names document summarisation and coding assistants as examples of long-prompt, prefill-dominant applications where RadixAttention delivers significant efficiency gains, which looks like a contradiction with SwiftCache. Both can hold: the task label does not decide anything, and what matters is whether the long context recurs across requests. Summarising a new document per request shares little; asking ten questions about one document shares a lot.

After a month of serving, the SGLang authors observed hit rates of 52.4% for LLaVA-Next-34B and 74.1% for Vicuna-33B, coming from common system messages, reused example images and multi-turn histories. For what those hit rates translate into in throughput and time to first token, see where a radix cache cuts LLM inference latency.

Why One Changed Token Breaks the Cache

The cache matches from the first token forward, so the first token that differs ends the match and everything after it is computed fresh. Including a timestamp precise to the second at the start of the system prompt is a common mistake that kills the hit rate.

The rules that keep the shared prefix stable follow directly from that:

  • Put stable content first and variable content last; in one SGLang paper example, moving a fixed instruction ahead of the {question} slot gave a longer shareable prefix.
  • Keep the context append-only and never edit earlier actions or observations.
  • Serialise deterministically, since many JSON libraries do not guarantee stable key ordering and can break the cache silently.
  • Avoid adding or removing tools mid-session, because tool definitions usually sit near the front of the context and any change invalidates everything after them.
  • Keep dynamic values such as dates, user IDs and request IDs out of the system prompt, or move them below the shared part.

Of all of these, nondeterministic serialisation is the one to check first in an agent stack, because it breaks the cache silently: the prompt reads the same to a human and differs to the tokenizer.

Scheduling for Cache Hits: Longest Prefix Match and Its Cost

Request order changes the hit rate, and SGLang uses a cache-aware scheduling policy to raise it. The SGLang paper defines the cache hit rate as cached prompt tokens divided by prompt tokens, and shows that a scheduler switching between unrelated requests causes cache thrashing. Visiting the tree in longest-shared-prefix-first order is equivalent to depth-first search, which is optimal for a batch when the cache holds at least the longest request. SGLang’s documentation suggests --schedule-policy lpm for workloads with many shared prefixes, noting that it reorders requests for more hits at the price of more scheduling overhead.

Longest prefix match has a fairness problem. A 2025 study of query scheduling under RadixAttention found first-come-first-served better at low request rates and LPM better at higher ones. LPM gives the best median time to first token, but a request whose prompt never overlaps enough can be left waiting; the proposed k-LPM takes k greedy prefix-match steps and then serves the oldest query, which kept median latency close to LPM while improving P99 in tests on SGLang. Whichever policy you pick, judge it on measured hit rate and tail latency together, as the verification section below sets out.

What Happens When the Radix Cache Fills GPU Memory

When the KV cache pool is full, the radix cache evicts cached prefixes to make room, and the eviction policy decides which go first. Only evictable leaves are candidates: nodes whose KV is present, that no in-flight request holds, and that are not shadowed by a child still holding KV; the root is never evicted. Once a leaf goes, its parent may become a leaf and re-enter the candidate set, so eviction walks a branch from its tip towards the root and shared ancestors such as a common system prompt survive until nothing below them remains.

The default policy is lru, and SGLang’s documentation calls it the right choice for most workloads. The alternatives trade recency for something else: lfu protects a stable hot set from bursts of one-off traffic, and tlru keeps only the history a conversation’s next prefill needs to meet a time-to-first-token budget, aimed at agentic and multi-turn traffic. The documentation also warns that lfu and slru hurt when prefix popularity shifts, because a prefix that earned a high count keeps its advantage after it stops being useful.

Agent workloads expose a key limitation of plain LRU. Agents’ long interaction histories are typically private, and when their aggregate demand exceeds GPU memory, synchronised accesses under LRU concentrate eviction on a few agents, causing large prefix recomputations. RR-Evict (2026) spreads tail eviction round-robin across idle agents and, in its SGLang implementation, reduced P99 time to first token by up to 75.4% relative to LRU. SGLang’s own session-aware eviction attacks the same gap by letting applications attach a stable session_id, which changes eviction order without pinning memory. How eviction plays out as concurrency rises is covered alongside the latency figures on the page about where a radix cache cuts inference latency.

The other answer to eviction is more cache capacity. SGLang HiCache extends RadixAttention with a HiRadixTree that references KV caches in GPU and CPU memory, with a controller that moves data across GPU, CPU and external storage tiers. The trade-offs of that design, including transfer overlap and write policies, belong to hierarchical caching for low-latency LLM inference.

How to Check the SGLang Radix Cache Is Working in Production

Read the hit rate first. SGLang exposes cache hit counters when the server runs with --enable-metrics, and its documentation advises starting with lru and changing the policy only against that measured hit rate. A hit rate near zero means the workload is not benefiting, whatever the configuration says. The Manus team, writing about production agents, argues that KV-cache hit rate is the single most important metric for an agent because it drives both latency and cost.

A short diagnostic sequence:

  1. Enable metrics and record the hit rate as cached prompt tokens over prompt tokens.
  2. If the rate is low on traffic you expected to share, diff two consecutive prompts at the token level and look for timestamps, reordered JSON keys or changed tool lists.
  3. If prompts are stable but hits still fall under load, check whether eviction is flushing prefixes before they return; this is where tlru, session IDs or HiCache tiers come in.
  4. If there are several replicas, check routing: SGLang v0.4’s cache-aware load balancer raised the hit rate from 20% to 75% on a perfectly balanced benchmark with multiple long prefix groups.
  5. Only then try --schedule-policy lpm, and compare P99 time to first token as well as the median.

If the hit rate is high and latency is still poor, prefix reuse is not your bottleneck, and the profile has to move to decode, batching or kernels. That is the useful property of this metric: it tells you whether a serving-path change is still available before the conversation turns to a different model.