Walk through how a prefix-cache hit changes the work that chunked prefill has to do
A continuous-batching scheduler (vLLM / SGLang) supports both prefix caching and chunked prefill. Walk through what happens to a new request whose first 5,000 tokens hit the prefix cache, when the total prompt is 7,000 tokens and the chunk size is 1,024. Explain how the two optimizations stack within one scheduler iteration.
Prefix cache reuses 5K tokens of existing KV, that prefill is skipped entirely.
Picture a teacher who needs to read a 7-page essay before grading. With prefix caching, she realizes she already read the first 5 pages last week and has notes, she just attaches those notes and starts fresh on page 6. Now she has 2 pages to read. Chunked prefill is her policy of never sitting down for a long uninterrupted read. She reads roughly a page (1,024 tokens), then briefly checks in with five other students' work in progress, then reads the rest of the second page, then checks in again. Every student gets a steady stream of attention instead of waiting an hour while she finishes one essay.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: prefix caching as KV-block reuse + chunked prefill as head-of-line-blocking fix + the specific 5K/2K/1024 walkthrough + how they batch into iterations + the orthogonality argument.
Real products, models, and research that use this idea.
- SGLang's RadixAttention combines prefix caching with continuous batching and is the canonical 2026 reference for this composition.
- vLLM 0.6+ supports automatic prefix caching with `--enable-prefix-caching` and chunked prefill via `--enable-chunked-prefill`; teams often run both together by default.
- Anthropic's prompt caching feature is the API-level analog of prefix caching, exposed to customers as billable cache reads at 0.1x rate.
- TensorRT-LLM's KV reuse feature plays the same role as prefix caching on NVIDIA's serving stack.
- Sarathi-Serve (Agrawal et al., 2024) is the academic origin of chunked prefill; vLLM and SGLang adopted the technique in production.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the scheduler decide which prefix-cache blocks to evict when HBM pressure rises?
QWhat's the right chunk size on an H100 running Llama 3.1 70B?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Believing the cache hit just speeds up prefill, it skips it entirely for the hit region. Or believing chunked prefill helps the cached portion, it doesn't; it only shapes the remaining work.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.