Sparse Attention at 10 Million Tokens: Breaking the Indexing Bottleneck
As context windows grow toward 10 million tokens, the bottleneck of long-context inference shifts from computing attention to finding relevant positions. This article explains why a naive indexer can dominate the cost of a sparse attention layer—reportedly up to 98% of prefill time in one experiment—while attention itself becomes cheap. It covers latent-space retrieval, hierarchical candidate selection, multi-path recall, reranking, the different optimization needs of prefill and decoding, how to interpret headline speedup numbers like 22.7x, and how to evaluate recall quality and end-to-end gains before deploying sparse attention in production.
1. The Long-Context Challenge Is Shifting from “Computing” to “Finding”
Long-context models must handle not only more text, but also longer-range dependencies: locating a constraint in a large document collection, recovering a decision made many turns earlier in a conversation, or combining evidence from different chapters to complete a reasoning task.
Traditional full attention lets every query position interact with all visible history. For an input of length N, the number of query-key interactions remains quadratic even with a causal mask. Growing the context from one million to ten million tokens—a 10x increase in length—can push the associated computation close to 100x, all else being equal.
The core idea of sparse attention is to stop having every query traverse all history, and instead select a small set of valuable positions for fine-grained computation.
But there is a hidden premise: finding those positions must itself be cheap.
If the system still compares against every historical position to pick a few candidates, it has merely turned expensive full attention into a slightly cheaper—but still quadratically growing—full scan. At the 10-million-token scale, that cost can become the dominant bottleneck.
Long-context optimization therefore has to answer two distinct questions:
- After selecting a few historical positions, how do we compute attention efficiently?
- Without scanning all history, how do we find candidates worth attending to?
The first determines the efficiency of sparse computation; the second determines whether sparse computation can scale at all.
2. Why the Indexer Can Cost More Than Attention Itself
The latency of a sparse attention layer can be decomposed as:
T_layer = T_projection + T_indexing + T_data_fetch + T_sparse_attention + T_misc
The indexing step typically includes generating retrieval representations, computing relevance scores, filtering candidates, and organizing the selected positions.
Suppose each query keeps k historical positions and the per-head feature dimension is d. An idealized sparse attention computation is O(Nkd). If k does not grow proportionally with N, this is far cheaper than the O(N²d) of full attention.
However, if the indexer still scans all historical keys for every query—just with the comparison dimension reduced to r—the indexing cost remains O(N²r).
Even when r is much smaller than d, the quadratic complexity has not disappeared.
In one experiment described in the source material, at 10 million tokens the indexing step accounted for roughly 98% of a single global attention layer’s prefill time in a certain class of model. The significance of this result is not that every model will show the same ratio, but that it exposes a structural imbalance worth watching: the part that executes attention is already sparse enough, while the part that decides where to attend is not.
Note that this ratio depends on the specific model, hardware, implementation, and measurement boundaries, and should not be treated as an industry-wide figure.
3. Latent-Space Retrieval: One Way to Cut Search Costs
A latent space can be understood as an internal representation space produced by a transformation. Raw queries and keys are usually high-dimensional, but the retrieval stage does not need every detail—it only needs to preserve the information relevant to candidate selection.
A general design pattern splits the process into “low-cost recall” and “high-precision computation”:
- Transform queries and historical keys into retrieval-friendly representations.
- Use these representations to produce a bounded candidate set.
- Apply more precise relevance scoring to the candidates.
- Run the final attention computation using the original (or task-required) high-precision representations.
The key distinction: retrieval representations decide what is “probably worth looking at”; attention representations decide “how to fuse it.”
However, moving into a low-dimensional latent space does not automatically remove quadratic complexity. If every query is still compared against all low-dimensional keys, the improvement is a constant factor, not a change in asymptotic order.
To scale further, the design must also incorporate hierarchical organization, block-level summaries, candidate routing, or approximate retrieval to reduce the number of historical positions actually visited. These are general design paths—the label “latent-space sparse attention” alone does not tell you which of them a specific implementation uses.
4. Designing a Scalable Candidate Selection Pipeline
4.1 Use Hierarchical Search to Avoid Position-by-Position Scanning
A common approach is to partition the history into blocks and build a summary representation for each block. A query first selects relevant blocks, then searches within those blocks for specific positions.
The search target changes from “all tokens” to “block summaries plus a few in-block tokens.”
But block summaries are not inherently reliable. A block may span multiple topics, and a single summary can mask rare but critical information. Block size, the number of summaries, and the candidate budget must be balanced: larger blocks make coarse filtering cheaper, but raise the risk of losing detail.
4.2 Use Multi-Path Candidates to Reduce Misses from a Single Router
Relying only on semantic similarity retrieval can miss information that looks dissimilar but determines the answer—for example, a passage defining an exception condition that later reasoning must obey, phrased very differently from the current question.
A more robust candidate set combines multiple sources:
- A local window to preserve continuity of nearby information.
- Global retrieval candidates to cover relevant long-range content.
- A few structural positions, such as chapter boundaries or task-defined key positions.
- Other deterministic positions retained as the task requires.
These candidates should be merged and deduplicated before attention runs. Otherwise, repeated hits from different paths waste budget and, if implemented carelessly, can even alter the computation’s semantics.
4.3 Separate Recall from Reranking
Low-cost recall usually aims for coverage rather than a perfectly precise ranking in one shot. You can generate a larger candidate set first, then compress it to the final budget with more accurate scores.
This reduces coarse-filtering errors, but reranking has its own cost. If the initial candidate pool is too large, or reranking requires frequent scattered data reads, the gains can be canceled out.
Candidate size should therefore be chosen jointly with memory layout, data-read volume, and compute parallelism—not by accuracy alone.
5. Prefill and Incremental Decoding Need Separate Optimization
During prefill, the system processes an entire input at once, building the visible range and running attention for a large number of query positions. This is where large-scale indexing computation and intermediate-result storage problems surface most clearly.
Incremental decoding is different: each step adds only a few queries, but the historical key-value state keeps growing. Even if per-step indexing is not quadratic, scanning tens of millions of historical positions can still add noticeable latency.
A complete solution must address both execution paths.
For prefill, focus on:
- Whether the index can be built in batches with reduced redundant work.
- Whether materializing a huge query–history score matrix can be avoided.
- Whether candidate generation can cooperate with block-wise computation.
- Whether causal visibility is strictly enforced so no future information is read.
For incremental decoding, focus on:
- How new key-value states are added to the index incrementally.
- Whether index updates block the next decoding step.
- Whether data access between queries and historical state is efficient.
- Whether index maintenance cost keeps growing over long-running sessions.
Strong prefill speedups do not imply decoding latency improves by the same ratio.
6. How to Interpret a “20x+ Speedup”
The source material reports that a latent-space sparse attention method achieved roughly a 22.7x prefill speedup on a single attention layer of a specific model at 10 million tokens, with an even higher figure on another test subject.
These numbers should be read as results within a specific experimental setup, not as a general promise for an entire model service.
A simple performance model explains why. Suppose indexing accounts for 98% of the original layer’s latency and everything else for 2%. If optimization only touches indexing and speeds it up by a factor of s, the layer’s total speedup is:
Speedup = 1 ÷ (0.02 + 0.98 ÷ s)
This shows that the larger the indexing share, the more valuable indexing optimization becomes; at the same time, once indexing is heavily compressed, the remaining components gradually become the new bottleneck.
At the whole-model level, you must also account for feed-forward networks, other types of attention layers, inter-device communication, and scheduling. A single-layer speedup therefore cannot be equated with full prefill speedup, let alone with the end-to-end speedup of a user request from submission to completion.
7. Accuracy Evaluation Cannot Stop at “Did It Find the Answer”
The direct risk of sparse selection is missing key evidence. Once the candidate set excludes a critical historical position, no amount of precision in the subsequent attention computation can recover the discarded information.
Evaluations should cover at least the following task types:
Precise localization. Can the model recover explicit facts, identifiers, or constraints buried in large amounts of distracting text?
Multi-position joint reasoning. The answer depends on several distant fragments, testing whether the candidate mechanism retains all the needed evidence simultaneously.
Global aggregation. The task requires synthesizing information across many regions rather than finding a single most-similar passage.
Position and distractor robustness. Place key evidence at the beginning, middle, and end, and add similar but incorrect content, to check whether performance remains stable.
You should also plot quality and latency curves across different input lengths and candidate budgets. An average score at one length says nothing about reliability on longer inputs or more complex tasks.
Candidate recall rate can serve as a diagnostic metric, but it does not fully equal final task quality. Whether the model actually relies on the recalled positions, and how multiple pieces of evidence jointly shape the output, require further analysis.
8. Engineering Rollout: Profile First, Replace Second
For real systems, the right order is to confirm the bottleneck before swapping attention structures.
First, build a baseline of per-component latency and memory usage, separating indexing, candidate selection, data reads, attention computation, and communication. Only when indexing genuinely occupies a large share will aggressive indexing optimization translate into meaningful gains.
Second, define the scope of the change. Some sparse schemes may require training or adapting retrieval representations—you cannot assume every existing model supports a lossless drop-in replacement. Even if the interface shape is compatible, output quality and numerical stability still need validation.
Third, record end-to-end latency, peak memory, concurrent throughput, and quality metrics together. New index structures consume memory, scattered reads hurt bandwidth utilization, and the fastest configuration in a single-run experiment may not suit high-concurrency serving.
Finally, keep fallback paths—such as a higher candidate budget for low-confidence or difficult requests—and include their extra cost in evaluation, rather than reporting only the ideal-path numbers.
Conclusion
The key change brought by 10-million-token contexts is that the cost of selecting information is becoming as important as the cost of processing it.
Sparse attention solves the problem of not having to look at all history; scalable indexing must additionally solve the problem of not having to scan all history. Latent-space representations can lower retrieval costs, but the real system-level gains depend on how candidates are organized, recall quality, memory access, and the coordinated design of the prefill and decoding phases.
To judge whether a solution works, you ultimately need to answer three questions at once: is the search cost controlled as context grows, is key evidence still reliably retained, and does the local optimization translate into reproducible end-to-end gains?
