Sparse Attention at 10M Token Context: Fixing the Indexer Bottleneck for Up to 22x Speedup

    As context windows move from 1M to 10M tokens, sparse attention solves the problem of attending to fewer tokens but leaves a hidden bottleneck: the indexer that decides which tokens to attend to. This article explains why index-time complexity still grows quadratically, how Latent Sparse Attention (LSA) compresses long sequences into a low-dimensional latent space to make retrieval nearly linear, where the speedup comes from, and what engineering teams should consider when adopting this approach.

    Sparse Attention at 10M Token Context: Fixing the Indexer Bottleneck for Up to 22x Speedup

    1. Long Context Is Becoming the Default, Not a Differentiator

    Over the past two years, long-context capability has shifted from a differentiating feature to a baseline specification. Context windows at the 1M token level are now an official default configuration for several model providers. In the second half of the year, mainstream open-source and commercial model families followed suit, introducing hybrid designs that combine sparse attention with linear attention at the architecture level.

    These approaches share a consistent technical judgment: each query should no longer traverse the entire token history, but instead select only a small set of the most relevant tokens for computation. This judgment has been repeatedly validated at the 1M scale—accuracy remains largely intact, while memory and compute overhead drop significantly.

    But as the context extends to 10 million tokens (10M), an initially negligible overhead starts to spiral out of control.

    2. The Real Bottleneck: Not Computing Attention, but Deciding What to Look At

    Consider a global attention layer performing prefill at 10M tokens:

    • The attention computation itself accounts for only a tiny fraction of total latency;
    • About 98% of the time is spent on the indexer—the scoring and selection process that decides which tokens to attend to.

    This reveals an easily overlooked fact: sparse attention solves “looking at less,” but it does not solve “finding slowly.” The complexity of the indexing stage still grows quadratically with context length, making it the core blocker for ultra-long contexts.

    The structural overhead can be expressed in pseudocode:

    1. # Naive sparse attention: indexing is still O(N^2)
    2. scores = query @ keys.T # [N, N], infeasible when N=10M
    3. topk_idx = topk(scores, k=2048) # k is small, but scoring is prohibitively expensive
    4. out = sparse_attend(query, keys, topk_idx)

    The nature of the problem therefore changes: accuracy is no longer the main concern; retrieval efficiency is.

    3. The Core Idea of LSA: Moving Selection into Latent Space

    A general technical approach that has recently emerged in the industry—Latent Sparse Attention (LSA)—targets exactly this stage. Its core idea is to avoid full scoring in the original token space. Instead, it first compresses the long sequence into a low-dimensional latent space, performs relevance selection in that latent space, and then maps back to the original tokens for attention computation.

    It can be broken down into four steps:

    1. Latent-space compression: Aggregate massive historical tokens into latent representations (latent slots) far fewer than N, reducing the candidate pool from tens of millions to thousands or hundreds.
    2. Latent-space retrieval: The query is scored only against latent representations via dot products, reducing complexity from O(N^2) to nearly linear.
    3. Mapping back to select tokens: Based on the membership relationship between latent representations and original tokens, locate the small set of tokens that actually need to participate in computation.
    4. Sparse attention computation: Run standard attention on the selected k tokens, where k is typically fixed at a few thousand.

    Illustrative flow:

    1. # LSA-style: indexing is nearly linear
    2. latent = compress(kv_history) # N -> M, M << N
    3. idx = topk(query @ latent.T, k=M_cand) # score in latent space
    4. tokens = gather(kv_history, idx) # map back to original tokens
    5. out = attend(query, tokens) # compute only on the small set

    4. Where the Gains Come From: A Shift in Complexity Class

    The speedup from LSA does not come from constant-factor optimizations, but from a shift in complexity class:

    • Original sparse attention: indexing O(N^2), attention O(N·k);
    • LSA: indexing approximately O(N·M + M^2), attention still O(N·k), where M is the number of latent slots and is far smaller than N.

    In public technical descriptions, this class of methods can speed up the prefill of a single attention layer by more than an order of magnitude at 10M tokens (gains vary by model size, with larger-parameter models benefiting more), while maintaining accuracy comparable to the original model across a range of long-context tasks. The implication for engineering practice is: the cost structure of long-context inference is rewritten, and prefill latency is no longer an insurmountable wall.

    5. Key Points for Engineering Adoption

    To borrow this idea in your own system, consider the following:

    1. Layered design: Local attention preserves accuracy, global sparse layers preserve coverage, and linear layers preserve cost efficiency—a hybrid of the three is a common industry practice.
    2. Tuning the number of latent slots: Too small an M loses information; too large degrades back to the original overhead. Ablations should be run per task.
    3. Coordination with caching: Latent representations can be maintained alongside the KV cache to avoid repeated compression.
    4. Monitoring and observability: Use general-purpose logging services and monitoring alerts to attribute latency across prefill stages and determine whether the indexer remains a hotspot.
    5. Elastic resources: Long-context inference is sensitive to compute fluctuations; container platforms and elastic scheduling can smooth out peaks.

    6. Conclusion

    In the era of 10M token contexts, the competitive focus has shifted from “can it see everything” to “can it quickly find the part it needs to see.” The answer from Latent Sparse Attention is to reduce the dimensionality of the selection process, bringing indexing back from quadratic to nearly linear. For developers, understanding this complexity shift holds more long-term value than memorizing any single model metric.