Why Long-Context Decoding Becomes Memory-Bandwidth Bound: The Trade-Offs of Sparse Attention
Long-context decoding is often limited by memory bandwidth rather than raw compute. This article explains why repeated KV-cache reads dominate latency, how page-level and token-level sparse attention reduce memory traffic, and what trade-offs arise in selection accuracy, indexing overhead, irregular memory access, and end-to-end performance. It also introduces a two-stage low-dimensional screening approach and provides a practical checklist for evaluating sparse attention in production.
1. The Bottleneck: Memory Access During Decoding
Large language models generate text autoregressively. At each step, the model produces one new token, appends it to the input, and proceeds to the next step. Recomputing the Key and Value vectors for all previous tokens at every step would cause the computational cost to grow rapidly with sequence length. Inference systems therefore store these vectors in a cache known as the KV cache, or Key-Value Cache.
For every newly generated token, the attention layer must read the historical KV cache. Its size can be estimated with the following formula:
KV cache bytes ≈ 2 × number of layers × number of KV heads × head dimension × context length × bytes per element
The factor of 2 accounts for the separate K and V tensors. The following figures are for illustration only and do not describe a specific model. Assume a model has 32 layers, 8 KV heads, a head dimension of 128, and uses 16-bit floating-point values, with 2 bytes per element. Each token would consume approximately 128 KB. With a context of 300,000 tokens, the total cache would be about 39 GB. If an accelerator provides 2 TB/s of memory bandwidth, reading the cache once would take approximately 20 milliseconds. As the context doubles, this time also roughly doubles.
The arithmetic intensity of this stage is low. Each historical token participates in only one vector dot product and one weighted sum, so the compute units spend much of their time waiting for data to arrive from device memory. For this type of data-movement-heavy workload, increasing peak compute throughput does little to reduce per-step latency. The primary optimization target is memory traffic.
2. The Basic Idea and Requirements of Sparse Attention
The motivation behind sparse attention is straightforward: the token being generated usually depends on only a small portion of the historical context. If the system can identify the most relevant historical tokens in advance, it can read only their corresponding cache entries and reduce memory traffic proportionally.
For this approach to work, two conditions must be satisfied.
First, the selection process itself must be inexpensive enough. If every step must read all Keys in full just to assign importance scores, the cost of selection can cancel out the savings from sparse reads, leaving little or no overall benefit.
Second, the skipped content must not contain information that is essential for subsequent generation. If relevant information is incorrectly classified as unimportant, output quality will decline. These errors can also accumulate along the generation chain.
The central design question for sparse attention is therefore not simply “Can we read less?” It is “How much does it cost to decide what to read, and what happens when the decision is wrong?”
3. Two Selection Granularities: Pages and Tokens
Most existing approaches can be broadly divided into two categories. They emphasize different points in the trade-off between memory efficiency and selection accuracy.
3.1 Page-Level Selection
Page-level methods group several consecutive tokens into a page and calculate a representative score for each page. Only pages with the highest scores are retained.
The main advantage is a hardware-friendly data layout. KV entries within a page are stored contiguously, allowing the system to use efficient batched memory-access paths and achieve high bandwidth utilization.
The drawback is coarse granularity. A single page may contain both important and irrelevant tokens. Keeping the page means reading the irrelevant content as well, while discarding it also removes any important tokens it contains. The larger the page, the more pronounced this trade-off becomes.
# Illustration: basic page-level selectiondef select_pages(query, page_summaries, budget):# page_summaries contains one representative vector per page,# so its size is much smaller than the number of tokensscores = [dot(query, s) for s in page_summaries]chosen = topk_indices(scores, k=budget)return chosen # Only the selected pages are read afterward
3.2 Token-Level Selection
Token-level methods assign a score to every historical token and retain only the highest-scoring subset. This provides finer granularity and, in theory, can preserve more truly relevant information under the same memory budget.
The problem is the resulting access pattern. Selected tokens are scattered throughout memory, turning the operation into many small, non-contiguous reads. Hardware generally handles these accesses less efficiently than contiguous reads, reducing effective bandwidth. In addition, assigning a score to every token requires extra data. If the data used for scoring is itself large, it can consume a significant portion of the bandwidth budget.
As a result, token-level methods may offer higher selection accuracy on paper, while their practical gains are reduced by inefficient memory access and selection overhead. A meaningful evaluation must consider both accuracy and end-to-end decoding speed rather than focusing on only one of them.
3.3 Understanding the Trade-Off
The two approaches represent opposite ends of the same trade-off. Page-level selection sacrifices precision for more efficient memory access. Token-level selection improves precision but pays for scattered reads and additional scoring work.
In practice, many systems choose an intermediate design. For example, they may first use a coarse-grained filter to identify candidate regions and then perform fine-grained selection within those regions.
4. Hidden Costs That Are Easy to Miss
Many discussions focus only on how much KV data is ultimately read, while overlooking several other costs.
Reading selection data. Both page-level and token-level selection require some form of index or summary data before candidates can be chosen. If this data grows with the context length, the selection stage itself becomes another linear source of overhead.
Maintaining indexes. During generation, the KV entries for each new token are written to the cache. The corresponding summaries or indexes must also be updated. This write overhead can become significant for long sequences, especially when page summaries need to be recomputed or aggregated.
Inefficiency from non-contiguous access. As discussed above, scattered reads reduce effective bandwidth. Even when the amount of data read decreases, latency may not fall proportionally.
Kernel scheduling and synchronization. Selection, collection, and attention computation are often divided into multiple steps. Each step can introduce kernel-launch and synchronization overhead. These fixed costs become especially visible when the amount of computation per decoding step is already small.
When evaluating a sparse attention method, measure all four categories of overhead and compare them with full attention.
5. Reducing Scoring Cost with a Low-Dimensional Subspace
Because selection itself has a cost, a natural direction is to make the scoring stage read less data. One general approach is subspace projection: map the query and Key vectors into a lower-dimensional subspace, retaining only a small number of dimensions that contribute most to the inner product. These reduced representations are then used to estimate relevance.
The benefit is that the scoring stage reads compressed representations instead of full Keys, substantially reducing memory traffic. After generating a candidate set, the system reads the complete KV entries for those candidates and performs the exact computation. This “coarse filtering followed by precise computation” structure keeps selection overhead relatively low.
Low-dimensional estimation inevitably introduces error. If the projected dimension is too small, important relevance signals may be lost. If it is too large, the cost advantage disappears. The projection dimension and candidate count therefore usually need to be tuned jointly for the target workload rather than fixed solely from general rules of thumb.
The following example illustrates the structure of this two-stage process. The function names are for demonstration only:
# Illustration: two-stage low-dimensional estimation and exact computationdef two_stage_attention(q, K_low, K_full, V_full, num_candidates, topk):# Stage 1: estimate relevance in a low-dimensional subspace# and read less dataapprox = K_low @ qcandidates = topk_indices(approx, k=num_candidates)# Stage 2: read complete KV entries for the candidates# and compute exact attention scoresexact = K_full[candidates] @ qchosen = candidates[topk_indices(exact, k=topk)]return softmax(exact[...]) @ V_full[chosen]
6. An Engineering Checklist
Before introducing sparse attention into a production system, review the following areas.
Validate quality. Compare full attention and sparse attention on long-context tasks that match the target workload. Do not look only at average scores. Also test questions involving details introduced early in the sequence, because these are especially vulnerable to incorrect pruning.
Preserve important positions. In practice, the first few tokens and a recent context window often have a strong effect on generation quality. Many approaches preserve both regions unconditionally and apply sparse selection to the middle portion.
Measure end-to-end speed. Record time to the first token, per-step decoding latency, and throughput. A reduction in the number of selected tokens is not sufficient by itself. Selection overhead and changes in memory-access efficiency must also be included.
Test the effect of batch size. As the batch size increases, different requests may select different entries, making memory access more complex. Testing should use the batch sizes expected in production rather than extrapolating from single-request results.
Monitor key metrics. Track memory usage, bandwidth utilization, and compute-unit utilization. If bandwidth is close to saturation while compute utilization remains low, memory access is still the bottleneck and sparsification is targeting the right problem. If bandwidth utilization decreases, investigate whether the access pattern has become too fragmented.
7. Conclusion
The core challenge of long-context decoding is that every newly generated token requires repeatedly reading a large amount of historical KV-cache data. This makes memory bandwidth the primary bottleneck, and simply increasing compute capacity cannot solve the problem fundamentally.
Sparse attention reduces memory traffic by reading only the relevant portions of the cache. Its benefits, however, depend on three factors: selection accuracy, the cost of selection itself, and memory-access efficiency. Page-level methods are memory-friendly but coarse-grained. Token-level methods offer finer accuracy but produce more scattered access patterns.
A practical system must balance these trade-offs while accounting for index maintenance, scheduling, synchronization, and other hidden costs. Only then can sparse attention deliver measurable gains under real decoding workloads.
