Sparse Attention at 10 Million Token Context: The Key to a 22x Speedup Is Fixing Indexing
Long context is shifting the cost structure of LLM inference. This article explains why sparse attention alone does not solve the problem at 10 million tokens: in a global attention layer, roughly 98% of prefill time can be spent on indexing rather than the attention math, and that indexing cost still grows quadratically. It walks through the two logical steps of an attention layer, introduces Latent Sparse Attention, which moves relevance scoring and Top-K selection into a compressed latent space while keeping aggregation in the original dimension, and covers the reported speedups of about 22.7x and 72.4x for a single layer's prefill. You will also find practical guidance on layer selection, chunking and parallelism, cache consistency, accuracy regression testing, and observability.
1. Long Context Is Rewriting the Cost Structure
Over the past two years, long context has moved from an experimental feature to a baseline specification. Million-token windows are becoming a default configuration for many model services, and architectures that mix sparse attention with linear attention are entering mainstream design. The original industry consensus was straightforward: if each query vector does not have to scan the entire history and only a few of the most relevant segments take part in the computation, you get a workable balance between accuracy and cost.
But as context keeps scaling toward the tens of millions of tokens, one step that used to be a minor share of the budget starts to run out of control. Take a single global attention layer: at 10 million tokens, during the prefill phase, roughly 98% of the time is not spent on the matrix multiplications of attention itself, but on the indexing step that decides which tokens to look at.
The nature of the bottleneck has changed. Sparse attention has repeatedly shown that attending to a small subset is enough to preserve accuracy. What actually holds back very long context is the act of finding that subset, and its cost still grows quadratically with context length.
2. Why Indexing Becomes the New Quadratic Bottleneck
An attention layer can be split into two logical steps:
- Scoring and selection: compute the relevance between each query and all historical tokens, then pick the Top-K.
- Weighted aggregation: perform the attention-weighted sum only over the selected K positions.
The first step scales with “number of queries × history length.” In prefill, the number of queries equals the history length, so the overall cost degrades to O(n²). The second step scales with n×K, which is nearly negligible when K is much smaller than n.
Traditional sparse attention:score = Q @ K_all^T # shape n × n, the source of the quadratic costidx = topk(score, K) # indexing decisionout = softmax(score[idx]) @ V[idx]
The problem is clear: sparsification compresses only the second step, while the first step remains fully intact. When n grows from 1M to 10M, indexing overhead grows by roughly 100x and eventually accounts for the vast majority of end-to-end time. This overhead is also shaped by memory bandwidth and the randomness of memory access, so it cannot be absorbed by simply adding more compute.
3. The Core Idea of Latent Sparse Attention
A recent paper from a startup research team working with universities proposes Latent Sparse Attention. Its starting point is to move “finding relevant segments” out of the original token space and into a compressed latent space.
There are three key elements:
- Reduced-dimension retrieval: first project the key vectors of historical tokens into a latent space much smaller than the head dimension, then perform relevance scoring and Top-K selection on that low-dimensional representation.
- Accuracy compensation: selection happens in the latent space, but weighted aggregation returns to the original dimension, so information loss from compression does not directly contaminate the output.
- Structural reuse: the latent representation can be shared with existing low-rank projection and cache compression mechanisms, reducing extra memory and bandwidth overhead.
A sketch of the implementation logic:
# Pseudocode: expresses the flow only, not a specific implementationlatent = proj_down(K_all) # n × d_latent, d_latent << d_headscore = Q_latent @ latent.T # low-dimensional scoring, much less memory trafficidx = topk(score, k) # indexing decision made in the low-dimensional spaceout = attn(Q, K_all[idx], V[idx]) # aggregation back at original precision
Because the dimensionality of scoring and selection drops substantially, memory traffic and computation in the indexing stage shrink together. The quadratic “shape” is replaced by a low-dimensional quadratic with a far smaller coefficient, so actual elapsed time drops significantly.
4. Where the Performance Gains Come From and How Large They Are
The paper reports that at 10 million tokens, prefill for a single attention layer achieves roughly 22.7x and 72.4x speedups on two models of different sizes, while maintaining accuracy close to the original models across a range of tasks.
The reason the gains span two orders of magnitude is largely structural: the higher the share of global attention layers, the larger the head dimension, and the more extreme the original indexing overhead, the more pronounced the relative gain from switching to low-dimensional scoring. This also suggests a practical engineering criterion: if a layer spends more than 80% of its prefill time on indexing, it is the prime target for optimization.
5. What to Watch When Putting It into Production
- Distinguish layer types: enable low-dimensional retrieval only for global attention layers, and keep local window layers and linear attention layers on their original path, so the gains are not cancelled out by extra overhead.
- Chunking and parallelism: split the history into chunks, do coarse filtering on chunk-level summaries first, then fine-rank within candidate chunks; this composes well with tensor parallelism and sequence parallelism.
- Cache consistency: the latent projection must be updated in sync with the key-value cache, and incremental decoding should avoid re-projecting.
- Accuracy regression validation: low-dimensional selection may miss a small number of highly relevant tokens, so run systematic regression on tasks such as long-document retrieval, multi-hop question answering, and code base comprehension.
- Observability: collect metrics such as indexing time share, candidate hit rate, and per-layer sparsity, and use monitoring and alerting to locate anomalous layers.
6. Practical Recommendations
For rollout order, start with a profile to confirm that indexing rather than computation is the bottleneck; then pilot the change on a single layer and compare accuracy and latency; finally extend it to all global layers and factor it into capacity planning. If you use cloud-based inference services, you can combine container platforms for elastic scaling, object storage for hosting long-text corpora, and logging plus monitoring and alerting to track tail latency.
The conclusion is direct: the next round of optimization at the million-to-ten-million token scale is not about computing faster, but about finding more cheaply. Moving retrieval into a low-dimensional latent space is currently a viable path for pulling indexing out of the quadratic trap.
