Ten-Million-Token Context: Indexing Bottlenecks and Optimization in Sparse Attention

    Sparse attention reduces the cost of attending over long inputs, but at ten-million-token scale, finding which positions to read can dominate total runtime. This article breaks down the per-layer cost of sparse attention, explains why low-dimensional scoring alone does not remove quadratic growth, and describes how hierarchical candidate selection works. It also covers where accuracy can be lost, how to interpret a reported 22.7x single-layer speedup, and how to evaluate these methods in production-like conditions.

    1. Why Looking at Less Is Not Enough as Context Grows

    The value of long-context models lies in fitting large amounts of material into a single inference pass. Examples include cross-file code, continuous business records, multiple technical documents, and long-running interaction histories. However, supporting longer inputs does not mean processing costs stay under control on their own.

    Standard causal self-attention requires each query position to be matched against all keys that come before it. Let N be the sequence length and d the attention dimension. The main attention compute in full prefill is typically O(N²d). Chunked computation can reduce the memory used by intermediate results, but it does not automatically remove all the matching work between queries and historical keys.

    Sparse attention changes this process. Each query accesses only a subset of candidate positions. If each query ultimately reads k key-value pairs, the main attention cost can be approximated as O(Nkd).

    However, this expression leaves out a key precondition: the candidate positions must already be found.

    If the system still has to compare each query with all historical keys to determine those k positions, it has only moved the expensive full matching into the indexer. The positions that finally take part in attention are few, but finding them remains expensive.

    Therefore, the core problem at ten-million-token scale is no longer only “how to reduce reads.” It also includes “how to decide what to read at low cost.”

    2. Splitting Sparse Attention Into Three Cost Stages

    Before discussing performance, it helps to separate three stages.

    The first stage is feature preparation. The model generates queries, keys, and values. Some methods also build low-dimensional representations for retrieval.

    The second stage is candidate selection. The system uses the query to pick historical positions that may be relevant. This step can include scoring, threshold checks, candidate ranking, and index maintenance.

    The third stage is the sparse attention computation itself. The system matches, normalizes, and aggregates values over the selected positions.

    The execution time of one attention layer can therefore be summarized as:

    T_layer = T_feature preparation + T_index construction and query + T_candidate reading and attention computation + T_data scheduling

    This view is closer to real engineering conditions than looking only at the attention operator.

    The original report measured a single-layer prefill test at ten-million-token input. In that test, the indexing stage accounted for about 98% of total time. This figure is a measurement under specific experimental conditions. It is not a general property of all sparse attention models. Still, it shows a representative problem: when candidate retrieval dominates, further optimizing an already fast sparse aggregation operator yields very limited gains.

    If one stage takes 98% of total time, then even if all other stages were completely eliminated, the overall speedup would be only about 1.02x. Optimization has to target the real bottleneck.

    3. Low-Dimensional Scoring Does Not Remove Quadratic Complexity

    A common idea is to map queries and keys into a lower-dimensional representation and compute relevance with those representations.

    If the original dimension is d and the retrieval dimension is r, with r much smaller than d, each relevance comparison becomes cheaper. But if each query still has to scan all historical keys, the retrieval stage still requires roughly O(N²r) work.

    This lowers the constant factor. It does not change how cost scales with length.

    When context grows from millions to ten million tokens, the length increases tenfold. The quadratic term may then grow by about a hundredfold. Savings from low-dimensional computation can quickly be offset by the larger input.

    This leads to an important test:

    Indexing optimizations for very long contexts must not only make each comparison cheaper. They also need to reduce the number of candidates that must be compared.

    When evaluating a method, do not ask only how much the retrieval representation is compressed. Also ask how many positions each query actually checks, and how that number grows as N increases.

    4. The General Approach to Latent-Space Sparse Retrieval

    Latent-space sparse attention can be understood from a general perspective. The method uses internal representations suited to retrieval to find candidates, then computes attention over that candidate set.

    The basic workflow includes the following steps:

    1. Generate retrieval representations for queries and historical keys.
    2. Organize historical positions into a structure that makes them easy to locate.
    3. Select a small set of candidate regions based on the current query.
    4. Choose specific positions within those regions.
    5. Aggregate attention using the keys and values at the selected positions.

    The retrieval representation does not have to be identical to the attention representation. The retrieval representation focuses on finding potentially relevant items at low cost. The attention representation focuses on computing accurate weights for the selected information.

    Low-dimensional mapping, grouping, routing, and hierarchical retrieval are general technical paths. They should not be taken as evidence that a particular study uses all of these mechanisms. For any specific method, its structure, training approach, and complexity should be judged from the full technical description.

    From an engineering standpoint, the key role of this design is to let low-cost retrieval narrow the search scope. It should not re-run a compressed version of full attention.

    5. How Hierarchical Filtering Narrows the Search Scope

    A design that is easy to understand is hierarchical filtering.

    Suppose a historical sequence of length N is divided into blocks of B tokens each. The system first compares the query with block-level representations, then selects a small number of blocks. Finally, it filters candidates inside those blocks.

    In a simplified model, each query traverses N/B block-level representations and checks specific tokens inside s selected blocks. The retrieval work can then be approximated as:

    O(N/B + sB)

    This expression only explains the trade-off. It is not a performance guarantee for all implementations. It shows that blocks that are too small enlarge the upper-level index. Blocks that are too large increase the search cost inside each block.

    When the whole prefill stage includes N queries, the upper level may still need a full traversal. In that case, the overall cost can still contain an O(N²/B) term. Blocking reduces overhead, but it does not automatically give strictly linear complexity.

    Reducing search cost further usually requires deeper routing structures, bounded probing budgets, or other approximate retrieval methods. These designs raise new questions. Is index construction expensive? Are updates convenient? Are important positions easy to miss?

    6. The Accuracy Boundary of Sparsification: Missed Information Cannot Be Recovered Through Normalization

    Candidate selection is approximate by nature. If a key position never enters the candidate set, the subsequent attention computation cannot read its information, no matter how precise that computation is.

    For this reason, “fewer candidates” should not be the only optimization goal. The real trade-off is between compute budget and information coverage.

    Different tasks put different demands on coverage. In long-document question answering, key evidence may appear only once. In code analysis, a definition and its calls may be far apart. In multi-constraint reasoning, several details that look minor may together determine the answer. Heavy reliance on locality or a single similarity metric can harm performance on these tasks.

    Several design approaches can improve reliability:

    • Keep a local window, so nearby context is not removed by mistake.
    • Reserve budget for long-range retrieval, so candidates are not concentrated only in nearby positions.
    • Introduce candidates from different sources, then merge them.
    • During training or adaptation, optimize the retrieval mechanism together with the final task objective.

    Each approach has costs. Multi-path candidates improve coverage but add deduplication, reading, and compute overhead. Fixed retained positions give stable access to some information, but they cannot guarantee coverage of the evidence any given task needs.

    So the accurate statement is that a method “maintains performance close to the baseline on specified evaluation tasks and budgets.” Broad claims that sparsification causes no loss in accuracy are not supported.

    7. How to Read a 20-Plus-Fold Speedup

    The original report gives a speedup of about 22.7x for the prefill of a single attention layer in one model at ten-million-token input. It also reports a higher speedup under another configuration. These results show that indexing optimization can offer substantial potential gains. They cannot be converted directly into speedup promises for the whole model or a business system.

    First, a single attention layer is not the whole model. Feed-forward computation, projections, normalization, and other operations still take time.

    Second, prefill is not full inference. Prefill processes the input sequence, while decoding generates output one step at a time. The two stages can have different comp