Using Span Queries to Optimize Cache and Attention Locality
PCPaul CastroNMNick MitchellNathan OrdonezTPThomas Parnell
Mudhakar SrivatsaAVAntoni Viros-i-Martin PCPaul Castro
NMNick Mitchell
Nathan Ordonez
TPThomas Parnell

Mudhakar Srivatsa
AVAntoni Viros-i-Martin
+6
This paper introduces the span query, a general structure expressing chat, RAG, inference-time scaling, and agentic workloads as expression trees of inference calls linked by commutativity constraints, differing from prior work by accounting for input order. Span queries can be automatically optimized for KV cache locality, and a 492-line change to vLLM enables high-performance execution, yielding 10-20x reductions in time-to-first-token for two non-chat use cases. Additionally, attention-locality optimization avoids the lost-in-the-middle problem, where an attention-optimized 2b-parameter model outperforms an 8b stock server in accuracy.

OpenReview · March 19, 2026