Sparse Attention at 10 Million Tokens: How Latent-Space Indexing Delivers a 22x Prefill Speedup
As context windows grow from millions to tens of millions of tokens, the bottleneck in sparse attention shifts from computing attention to deciding which tokens to attend to. This article breaks down why the indexing stage becomes a new quadratic cost, introduces Latent Sparse Attention (LSA), which moves selection into a compressed latent space to make indexing near-linear, and reports the published prefill speedups of roughly 22.7x and 72.4x on two model sizes at 10 million tokens. It also covers where this optimization pays off, where it does not, and the engineering practices for adopting it safely.
1. Background: Once Context Passes 10 Million Tokens, the Cost Structure Inverts
Over the past two years, long context has quickly become a default expectation for LLM services. Context windows of a million tokens have moved from a “highlight feature” in a handful of demos to a standard published spec on many platforms. One of the main technical threads behind this shift is that each query no longer scans every historical token; instead, it selects a few of the most relevant segments to participate in the computation. That is the basic idea of sparse attention.
The approach has been validated repeatedly at the million-token scale: as long as the selection is accurate, attending to only a small fraction of the history is enough to preserve quality. But as context pushes on toward 10 million tokens, an overhead that once looked negligible starts to spiral.
Take one global attention layer in a mainstream open-source model. At 10 million tokens, during the prefill stage, roughly 98% of the time is not spent on the attention computation itself, but on the indexer that “decides which tokens to look at.” This number exposes an easily overlooked fact: sparsification saves computation, but the cost of “finding who to look at” still grows quadratically with context length.
The nature of the problem has therefore changed completely:
- The early conflict was “full attention is too expensive to compute,” and the answer was sparsification.
- The current conflict is “the selection step of sparsification is too expensive to compute,” and the answer requires rebuilding the indexing mechanism itself.
2. Root Cause: Why “Selection” Becomes the New Quadratic Bottleneck
To understand this, split the attention layer into two logical stages.
The first stage is indexing (Index / Select): compute a relevance score between each query and all historical tokens, then pick the top-k positions. The second stage is aggregation (Aggregate): take a weighted sum over only the selected k key/value pairs.
Sparse attention optimizes only the second stage, reducing complexity from O(n²) to roughly O(n·k). But the first stage is still O(n²): each of the n queries must be scored against n keys. When n grows from 10⁶ to 10⁷, the second stage stays essentially flat because k is fixed, while the first stage grows by about 100x and ends up consuming nearly all of the time.
Schematically, the structure looks like this:
# Simplified illustration: the two stages of sparse attentionscores = q @ k.transpose(-1, -2) # [n, n] quadratic cost, indexing stageidx = scores.topk(k, dim=-1).indices # select top-kout = sparse_aggregate(q, k, v, idx) # ~n*k, aggregation stage
The genuinely expensive piece is that [n, n] score matrix, and it exists precisely to serve “selection.” As long as scoring happens in the original token dimension, any engineering optimization (a better kernel, a more memory-efficient implementation) can only change the constant, not the order of magnitude.
3. The Core Idea: Move “Selection” into Latent Space
A recent paper from a startup research team working with academic collaborators proposes Latent Sparse Attention (LSA). The core idea is not complicated, but it targets the right spot: do not perform selection in the original token dimension. Instead, first compress the history into a low-dimensional latent space, then do the retrieval there.
It can be summarized in three steps:
- Compress: map the long history sequence into a set of latent vectors (latent slots) whose count is far smaller than n, where each latent vector carries summary information about a segment of the history.
- Retrieve: the query is scored only against these m latent vectors (m ≪ n), and the few most relevant slots are selected.
- Backfill: using the selected slots, go back to the original tokens to locate the segments that actually need to be aggregated.
Because retrieval happens over a latent space of length m, the complexity of the indexing stage drops from O(n²) to roughly O(n·m), which is near-linear when m is far smaller than n. This is exactly where the “one more order of magnitude at 10 million tokens” comes from.
A pseudocode expression closer to an implementation:
# Latent Sparse Attention (illustrative)latent = compress(history, m) # [m, d], m << nscore = q @ latent.transpose(-1, -2) # [n, m], near-linearslots = score.topk(top_slots, dim=-1) # select a few latent slotsout = gather_and_aggregate(q, k, v, slots)
It is worth stressing that what preserves accuracy in this kind of method is information fidelity in the two stages of compression and backfill: the latent vectors must be able to represent the semantics of the interval they cover, and the backfill must map the latent-space selection accurately back to original positions. This is also the part that deserves the most attention when evaluating such an approach.
4. Results and Applicability: Where the Order-of-Magnitude Gain Comes From
According to the public description, at 10 million tokens the method delivers roughly 22.7x and 72.4x speedups for a single attention layer’s prefill (for two different model sizes), while maintaining accuracy close to the original model across multiple tasks. The gap between the two numbers also shows that the larger the model and the higher the share of original indexing overhead, the more pronounced the relative gain from latent-space retrieval.
In terms of applicable scenarios, this kind of optimization delivers the most value for:
- Workloads where prefill dominates, such as ingesting a long document in one pass or building repository-level context;
- Tasks where context length far exceeds output length, such as long-document summarization and cross-document retrieval QA;
- Service deployments that need to offer long context under limited memory and compute.
Conversely, if a task itself produces very long output and the decode stage dominates, the benefit of indexing optimization is diluted.
5. Engineering Adoption Notes
To borrow this idea in your own system, focus on the following:
- Measure first, then optimize: use a per-layer timing breakdown to confirm the share taken by the indexing stage, and avoid investing in the wrong bottleneck.
- The latent space size m is a tunable knob: a larger m means higher fidelity but slower speed, so run sensitivity tests against your task.
- Match the compression strategy to the task: different tasks have different granularity requirements for the “history summary,” which need to be validated separately.
- Keep it decoupled from existing infrastructure: this kind of optimization is an inference-side change, and can rely on general-purpose container platforms, logging services, and monitoring and alerting systems for canary rollout and observability, with no changes to business code.
- Build a regression evaluation set: put accuracy evaluation up front to ensure the speedup does not come at the cost of quality.
6. Conclusion
The competition in long context is shifting from “can it handle that much context” to “is handling that much context still cost-effective.” When indexing cost replaces computation cost as the main conflict, the real breakthrough is not being more sparse, but finding more intelligently. Latent Sparse Attention’s answer is to swap out the search space. For teams building long-context capabilities, this points to a clear engineering path: first locate the cost structure, then rebuild the indexing mechanism, and finally use an observability system to safeguard launch quality.
