Zhaozhao
← All notes

The quiet cost of long context

29 October 2026 · 8 min read

Close-up of server racks with status LEDs in a dim data centre aisle

Context windows have grown by roughly two orders of magnitude in three years, and the marketing has kept pace. What has not kept pace is the intuition most engineers carry about where the cost of a long request actually goes. The number on the pricing page is per token; the bill is not linear in the way people assume.

Start with the cache

The KV cache is the cleanest place to see the problem, because you can compute it exactly. For a transformer with L layers, H key-value heads, head dimension d, and fp16 storage, the cache per token is:

bytes_per_token = L × 2 × H × d × 2

Take a 70B-class model with 80 layers, 8 KV heads, and head dimension 128. That gives 4 KB per token per layer, or 320 KB per token in total.

0 100 200 300 GB 10 41 164 320 41 32K 128K 512K 1M context length (tokens) dense fp16 GQA-8 + int8 cache
Figure 1 — KV cache footprint for a 70B-class model. Grouped-query attention plus int8 cache reduces the footprint by roughly 8x, which is the difference between impossible and merely expensive.

This is why long-context serving is not simply "the same thing but longer". At 1M tokens the cache alone exceeds any single accelerator, before you have stored a single weight. Every technique in the long-context toolbox — grouped-query attention, quantization, paged allocation, offloading — exists to fight this one number.

Grouped-query attention is the big lever: going from 64 KV heads to 8 cuts the cache by 8x. Quantizing the cache to int8 halves it again. Together, that 320 GB becomes 20 GB, which fits. But note what happened — you did not make long context cheap, you made it merely possible.

Prefill is the latency wall

The second cost is time, and it lands almost entirely before the first output token.

Prefill processes the whole prompt in parallel, which is good for utilization but means the work scales with prompt length. A million tokens at a generous 20K tokens per second of prefill throughput is still fifty seconds of silence before the model says anything. Users do not experience that as "long context". They experience it as a broken product.

Decode, by contrast, is one token at a time and dominated by memory bandwidth — every step re-reads the weights and the growing cache. At long context, decode gets slower as the cache grows, not because the math changed but because there is more memory to move per token.

Long context is paid for twice: once in prefill latency, and again in every subsequent decode step.

The quality assumption

There is a third cost that does not show up in any profiler. A model that accepts 1M tokens does not reliably use 1M tokens.

The "lost in the middle" effect is well documented and has not been fully solved by scale. Information placed in the middle of a long context is retrieved less reliably than information at the edges. Effective context — the length at which retrieval accuracy stays high — is consistently shorter than the advertised maximum, often by a large factor.

This matters for architecture decisions. If effective context is 30K and you are paying for 200K, you are buying latency and memory to store text the model will not attend to properly. The honest move is to measure effective context on your own task distribution rather than trusting the spec sheet.

What this implies for design

A few conclusions I have become fairly confident about:

Long context is a real capability and I am glad it exists. But it is priced like a feature and costs like an architecture. Treating it as the latter is the difference between a demo that impresses and a service that survives its own traffic.

serving memory latency