Per-token decode time grows linearly as a chat session lengthens, debug it
An interactive chat product reports that TPOT starts at ~40ms and climbs to ~120ms by the time a session reaches 30k tokens of history. Diagnose the cause from first principles, then list the four most impactful mitigations a serving team can ship without retraining the model. Quantify each lever's effect where you can.
TPOT tracks bytes streamed per decode step.
Picture a librarian who has to fetch every book on a long shelf before answering each question, then re-shelve them. At first the shelf is short and each question is fast. As more questions come in the shelf grows, and the librarian's arms cover more distance every single time. The time to answer one question grows in lockstep with the shelf length. The fix is not to make the librarian faster, but to shorten the shelf. You can let them skip the books they have already memorised (prefix cache), use thinner books (compressed cache), remove the middle of the shelf and keep only the start and the recent end (sliding window), or just cap how long the shelf is allowed to grow. The shelf length is what sets the speed.
Detailed answer & concept explanation~8 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.
6 min: decompose bytes-per-step into weights and KV + show KV grows linearly with T + walk through prefix caching, GQA/MLA, StreamingLLM, history compaction + FP8 KV as a fifth lever + tie it all to the bytes-per-step invariant.
Real products, models, and research that use this idea.
- vLLM and SGLang ship automatic prefix caching across requests with content-hashed paged KV blocks as a default in 2026.
- Llama 4 Maverick uses GQA-8, dropping KV memory roughly 8x versus full multi-head attention at the same model size.
- DeepSeek V3 and V4 use MLA to compress KV to a shared 512-dim latent, giving 10 to 100x effective KV shrinkage and serving 128k context cheaply.
- Anthropic Claude prompt caching and OpenAI cached input pricing are product surfaces of the same engine-level prefix-caching mechanism.
- StreamingLLM (Xiao et al. 2023) introduced the attention-sink trick used in many long-context chat stacks to keep KV bounded.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does prefix caching shrink HBM pressure even more than naive cache reuse suggests?
QHow does MLA achieve 10 to 100x KV shrinkage without obvious quality loss?
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.
Blaming the slowdown on compute or model size, when the model itself is unchanged. The variable is sequence length T, and the cost it changes is HBM bytes per step through the KV-cache term, not the weight term.
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.