Sparse Attention at 10 Million Tokens: The Indexing Bottleneck and the 22x Speedup

    As context windows scale from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to finding which tokens matter. This article explains why the scoring and top-k selection stages grow quadratically with sequence length, and how Latent Sparse Attention (LSA) moves scoring into a low-dimensional latent space to reduce indexing to near-linear growth. It covers the core design, reported prefill speedups of roughly 22.7x and 72.4x at the 10-million-token scale, and the engineering considerations for adopting the approach: choosing the number of latent slots, block granularity and alignment, KV cache coordination, accuracy regression testing, and coexistence with linear attention and hybrid architectures.

    1. The New Bottleneck in Long Contexts: From Computing Attention to Finding Attention

    Over the past two years, competition in long-context capability has centered on window size. Million-token contexts have gradually become a default specification for many model services, and hybrid architectures combining sparse attention with linear attention are being used to balance accuracy against cost. These approaches share a common premise: each query no longer scans the entire token history, but instead selects a small set of the most relevant segments to participate in the computation.

    Under a million-token window, this premise works well. But as the window expands further to tens of millions of tokens, an initially unremarkable cost begins to spiral out of control. Take a global attention layer as an example: at the ten-million-token scale, the prefill phase spends most of its time not on the attention matrix multiplications, but on the indexing step that decides which tokens to look at.

    The nature of the problem therefore changes. Sparse attention has repeatedly demonstrated that “looking at only a small portion” is enough to preserve accuracy. What actually blocks extreme long contexts is that the cost of “finding that small portion” still grows quadratically with context length. In other words, the indexer has replaced attention itself as the new compute black hole.

    2. Why Indexing Costs Grow Quadratically

    Naive sparse attention can be broken down into three steps:

    1. Compute a relevance score between each query and all historical tokens;
    2. Select the top-k most relevant tokens;
    3. Run attention over only those k tokens.

    The third step is linear in complexity and manageable. The problem lies in the first and second steps. Scoring requires each query to interact with every key, which is O(n²); top-k selection typically also requires additional sorting or heap maintenance in engineering practice, adding a non-trivial constant cost. When n grows from 10⁶ to 10⁷, this portion of the cost grows roughly a hundredfold, while the attention computation itself barely changes because k is fixed.

    Schematically, the logic looks close to the following:

    1. # Naive sparse attention: the indexing stage becomes the bottleneck
    2. scores = query @ keys.T # O(n^2), high in both memory and compute
    3. idx = topk(scores, k) # selection cost grows with n
    4. out = attention(query, keys[idx], values[idx]) # O(n*k), relatively cheap

    The conclusion is direct: as long as “scoring + selection” is still performed in the original token space, every order-of-magnitude increase in window size increases indexing cost by two orders of magnitude.

    3. The Core Idea of Latent Sparse Attention

    A recent paper from a startup research team in collaboration with universities proposes Latent Sparse Attention (LSA). Its starting point is not to further optimize the top-k implementation, but to change the space in which scoring happens: instead of having the query interact with raw tokens one by one, the long sequence is first compressed into a low-dimensional latent space, coarse-grained relevance localization is performed in that latent space, and fine-grained computation is then carried out back in the original space.

    It can be understood as “check the table of contents first, then read the body text”:

    • Latent space construction: historical tokens are chunked or aggregated and mapped into a number of latent representations (latent slots) far smaller than n, where each latent representation carries a continuous span of context;
    • Latent space retrieval: the query computes similarity only against these few latent representations, reducing complexity from O(n²) to O(n·m), where m is the number of latent slots and m ≪ n;
    • Backfilling and fine computation: based on the hit latent slots, candidate token blocks are located, and top-k plus attention are executed only within those blocks.

    The key is that the quadratic term is replaced by “n multiplied by a very small constant.” The indexing stage no longer grows with the square of the window, but grows approximately linearly. The paper reports that at the ten-million-token scale, a single attention layer’s prefill is sped up by about 22.7x (using a certain class of hybrid sparse architecture model as the baseline), and by about 72.4x on another model, while maintaining accuracy close to the original models across a range of tasks. The difference in speedup comes mainly from differences in the baseline indexing implementation and latent slot configuration, rather than from limited applicability of the method itself.

    4. Engineering Implementation Points

    To draw on this idea in your own inference pipeline, several points deserve attention:

    1. The tradeoff in the number of latent slots m. Too small an m loses localization accuracy and leads to insufficient recall of candidate blocks; too large an m degrades back to the original space. In practice, m is usually made to grow sublinearly with the window, for example on the order of √n, and calibrated on a validation set.
    2. Chunk granularity and alignment. The mapping between latent representations and token blocks must balance continuity with hardware friendliness; aligning block size to a suitable multiple of the compute unit can significantly improve memory access efficiency.
    3. Coordination with the KV cache. Build the latent index during prefill and maintain it incrementally during decode; when new tokens are appended, the affected latent slots must be updated in sync to avoid inconsistency between the index and the cache.
    4. Accuracy regression evaluation. Compression introduces information loss, so systematic evaluation is required on long-range dependency tasks such as long-document retrieval, multi-hop question answering, and repository-level code understanding, with particular attention to the recall of “needle” information.
    5. Coexistence with linear attention and hybrid architectures. LSA addresses the indexing bottleneck and does not preclude the contribution of linear attention to state compression; the two can be combined.

    At the deployment level, this kind of capability is typically carried by a container platform hosting the inference service, with object storage holding model and index artifacts, and log services plus monitoring and alerting observing prefill latency, index hit rate, and memory usage, forming an observable tuning loop. General-purpose cloud capabilities are sufficient to support the engineering practices above, without relying on any particular vendor’s proprietary interfaces.

    5. Conclusion

    In the era of ten-million-token contexts, the core tension has shifted from “can we afford to compute attention” to “can we find the relevant segments fast enough.” The value of Latent Sparse Attention lies in reducing the indexing stage from quadratic to near-linear, making the prefill cost of extreme long contexts predictable again. For developers, the real implementation focus is not chasing the largest window number, but making the three things—indexing, caching, and evaluation—solid. That is what determines whether long-context capability stays in a demo or can enter production.