The Indexing Bottleneck of Sparse Attention at 10M Tokens and How to Address It

    As context windows scale from 1M to 10M tokens, the cost of sparse attention shifts from attention computation itself to the indexing step that selects which tokens to attend to. This article explains why the O(N²) indexing stage becomes the dominant bottleneck at ten-million-token scale, why it was acceptable at one-million scale, and how the two phases of sparse attention differ in complexity, with pseudocode illustrating the gap.

    1. Scaling Context to Ten Million Tokens Introduces New Costs

    Over the past year, ultra-long context has become a key battleground in large model development. Some models and services now treat a one-million-token (1M) context as standard, and some combine sparse attention with linear attention to keep inference costs under control for long sequences.

    These approaches share a common idea: instead of computing attention between each query and the entire history of tokens, only a small set of relevant tokens is selected for the computation. This is sparse attention. At the 1M-token scale, this approach delivers stable results in both accuracy and speed.

    Things change when the context scales to ten million (10M) tokens. According to reported material, during prefill on a global attention layer using sparse attention, roughly 98% of the time was spent on the Indexer, while the actual attention computation accounted for only a small fraction. The experimental conditions behind this figure should be verified against the original source, and this article makes no further extrapolations from it. But it points in a clear direction: the optimization focus may have shifted from attention computation itself to the step of “figuring out which tokens to look at.”

    2. Why the Bottleneck Shifts

    2.1 The Two Phases of Sparse Attention

    A typical sparse attention layer works in two steps.

    Step one: indexing and selection. For each query, a scoring method (for example, computing similarity between the query and compressed key representations) is used to select the Top-K most relevant tokens from all N historical tokens.

    Step two: attention computation. The query attends only to those K tokens using standard attention.

    The second step has complexity O(N·K). Since K is typically much smaller than N—common values range from a few hundred to a few thousand—this step is already quite cheap. The problem lies in step one: scoring requires each query to interact with all N index keys, giving a complexity of O(N²).

    2.2 Why It Wasn’t Obvious at the Million-Token Scale

    At 1M context, the indexer is also O(N²), but the per-scoring vector dimension is relatively low, and implementations use optimizations such as blocking and quantization, so the absolute latency remains acceptable.

    When N grows by 10×, the O(N²) term grows by 100×, while the O(N·K) term grows by only 10×. Because the two terms scale at different rates, the indexing cost overtakes attention computation at the ten-million-token scale.

    The memory issue here comes with a caveat. If one were to explicitly materialize an N×N scoring matrix, a 10M×10M matrix could not fit in GPU memory. Real implementations typically process in blocks or in a streaming fashion, so the main pressure falls on compute volume, Top-K sorting, and memory bandwidth.

    The following pseudocode illustrates the difference between the two phases.

    1. # Phase 1: index scoring, complexity O(N^2)
    2. # scores: [num_queries, num_keys]
    3. scores = queries @ index_keys.T # score every query against all keys
    4. topk_idx = scores.topk(K, dim=-1).indices # select Top-K for each query
    5. # Phase 2: sparse attention, complexity O(N*K)
    6. selected_k = gather(keys, topk_idx) # [N, K, d]
    7. selected_v = gather(values, topk_idx)
    8. # each query attends only to its K selected keys

    2.3 The Nature of the Problem

    Sparse attention has shown that attending to only a small fraction of tokens usually preserves model accuracy. What truly blocks ultra-long context is that the process of “finding that small fraction” still grows quadratically with context length. In other words, the computation has been sparsified, but the retrieval has not.