Manuscript Offprint

arXiv:2610.09139

Breaking the Space Barrier and its Application to Language Model Inference

Arip Asadulaev

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Language models are more and more often asked for structured output: JSON that follows a schema, or a tool call with typed arguments. A small machine, an automaton, enforces the format by forbidding the tokens that would break it. We observe that this machine has a rare property: from any of its states, each token leads along exactly one path. Graphs in which only a few paths join any two points are a classical object of complexity theory, and our theoretical result settles an open question about them: one can decide whether such a graph connects two points while verifying that it really has few paths, with very little memory. Precisely, the problem lies in the classes ReachUL, LOGDCFL, C=L and SC², and needs only O(log⁡2n/log⁡log⁡n)O(\log^2 n/\log \log n) space, below the classical O(log⁡2n)O(\log^2 n) of Savitch's theorem. The constructions behind the proofs become an inference engine: text the format forces is written without running the model, the mask is recomputed on the GPU without any table, recursive formats use a small stack, every output stays valid under a token limit, and independent fields are decoded in parallel and verified. On one 16 GB Apple M2 Pro with Qwen3.5-2B and 4B, against MLX with llguidance, the standard setup for this hardware, schema-constrained extraction finishes 1.2–1.3× sooner with the same answers, a grammar costs 3 MB instead of up to 1.5 GB, one server holds sixteen grammars where tables run out of memory, and sixteen tool-calling agents finish 2.5× sooner.

1 Introduction

A language model writes text one token at a time. When an application needs the output in a fixed format, for example a JSON object with given keys or a call to a tool with typed arguments, the format is compiled into a small machine called an automaton. At every step the automaton says which tokens are allowed; all others are forbidden (masked). This is constrained decoding, and libraries such as llguidance [23], Outlines [35] and XGrammar [11] provide it. On a laptop it is usually a cost: the model runs as before, and the mask is extra work at every step.

Our starting observation is simple. Fix a state of the automaton and a token. The token is a fixed string of bytes and the automaton is deterministic, so reading the token leads to exactly one next state. If we draw all the ways of reading tokens from a state, we get a tree: there is exactly one path to every point. Graphs with this property, and more generally graphs in which at most k paths join any two points (k-strongly few graphs), are a classical topic of complexity theory, the field that studies how much time and memory problems need.

The theory. Apers and Edenhofer [3] recently asked a precise question about such graphs. Suppose you are handed a graph and two points, and you must answer whether the graph has at most k paths between every pair of points and the second point can be reached from the first. How much memory does a classical computer need? The difficulty is that nothing is promised: the graph may contain cycles or astronomically many paths, and the algorithm must notice. We answer the question. The problem can be solved with memory logarithmic in the input size by a machine that never has

Preprint.

Table 1: Headline results on one Apple M2 Pro (16 GB), Qwen3.5-2B / 4B in 4-bit precision, greedy decoding. The baseline is llguidance with MLX: in our decode loop with the same kernels for the first two rows, stock mlx-lm with llguidance for the last three.

SettingMLX + llguidanceSTCON (ours)
six JSON extractions, decode time (2B / 4B) memory of a 1,106-state tool-call grammar2.41 / 4.59 sdoes not compile (token table: 824 MB)1.89 / 3.89 s3.4 MB
sixteen tool-calling agents, wall time (2B) eight concurrent tool-call requests (2B) eighteen JSON jobs, 8 parallel slots, keys-only prompt (2B)74.6 s134 tok/s6.12 s29.3 s410 tok/s3.83 s

Figure

Figure 1: What one model run costs (Qwen3.5-2B on an M2 Pro). A run over 8 tokens costs 1.6×1.6 \times a run over one, not 8×8 \times, because the run is dominated by reading the weights. So skipping runs saves time, and tokens added to a run that happens anyway are almost free.

two ways to reach the same state (the class ReachUL), by a deterministic machine with a stack (LOGDCFL), and by a single algorithm that is fast and uses O(log⁡2n)O(\log^2 n) memory at the same time (SC2\mathrm{SC}^2); it also lies in C_L\mathrm{C\_L}, and it needs only O(log⁡2n/log⁡log⁡n)O(\log^2 n / \log \log n) memory, less than Savitch's classical O(log⁡2n)O(\log^2 n) for reachability. Section 3 explains these results without assuming any background; the proofs are in Appendix B.

The practice. The proofs are built from a few constructive ideas: stop every search at a budget, certify a structure before counting on it, recompute along unique paths instead of storing, keep a small capped stack, and split a problem at points every path must cross. Applied to the graph of one decoding step, these ideas become an engine (Section 4). Text the format forces is written without running the model, so a constrained output needs fewer model runs than a free one; the mask is recomputed on the GPU in microseconds, so no table is stored; forced text is split into tokens exactly as the model's tokenizer would split it; recursive formats run on a small GPU stack; outputs stay valid under any feasible token limit; and independent fields of a JSON object are decoded in parallel and then verified. Table 1 summarizes the gains against MLX [17] with llguidance, the standard way to run constrained decoding on Apple hardware.

Contributions. (1) We settle the classical complexity of total few-path reachability, the question of Apers and Edenhofer, with three new constructions, and extend them to arbitrary walk budgets, a compiler for programs with few computation paths, completeness results, a sharp threshold phenomenon and a structure theory (Section 3, Appendix B). (2) We turn these constructions into six exact mechanisms for constrained decoding, each with a theorem (Section 4, Appendix C). (3) We build them into an engine on MLX and measure speed, answer quality and memory (Section 5, Appendices E–H).

References (28)