Manuscript Offprint

arXiv:2610.19801

Delta Tokenizer: Reference-Identical Tokenization of Session Deltas and Segment-Parallelism for Long Prompts on Multicore CPUs

Zhenyu Zhang, Zhichao Cao

Abstract

An agent that drives an LLM sends the model the same conversation again and again, and each turn adds only a little text at the end. Inference engines already avoid redoing the model's work for the part that has not changed: the KV cache holds the state of the shared prefix, and only the new tokens pass through the model. However, tokenization has no such shortcut. The CPU front end of the serving engine converts every request back into token IDs from its first character, so this stateless step is paid in full on every turn. As a result, it lengthens the time to first token and consumes more CPU resources. Even worse, longer contexts and longer sessions widen the gap.

To address those issues, we present Delta Tokenizer, a CPU tokenization front end that reads each request as a change to the request before it (i.e., tokenizing the delta) in the same session. Delta Tokenizer retains the token sequence of the earlier turn, encodes again only the appended text and the short tail whose tokens the append could affect, and joins the two only at a position the tokenizer's splitting rules themselves cannot move, which keeps the result exact. A request with no state to reuse must still be encoded from scratch. For long requests of this kind, Delta Tokenizer cuts the text where practical tokenizers already keep neighboring pieces independent, encodes the pieces on several cores at once, and concatenates the outputs into the reference encoding, exactly. Delta Tokenizer leverages a shared CPU pool to schedule these chunks together with the short incremental updates, so an update runs between two chunks rather than behind an entire long job.

Across our experiments, the incremental path shortens the tokenization of a session turn by roughly 40×40\times relative to the Hugging Face reference tokenizer, and on 16 cores the chunk-parallel path encodes a request of four million characters 8.2×8.2\times faster than a serial encode and 1.6−2.1×1.6-2.1\times faster than LoPT. Inside SGLang, Delta Tokenizer reduces the median time to first token, or TTFT, through the chat interface by 59% at 100K tokens, which is the median context of the agents we traced, and brings the P99 TTFT of agent sessions down 9.5×9.5\times under load and 23×23\times when long requests tie up the front end without ever reaching the model. When such requests are admitted and the model serves them from its prefix cache, the P99 TTFT of agent turns stays about 7×7\times lower, and about 20×20\times lower on a server with one core or a smaller model. Every output we checked matches the reference, among them 41.8 billion documents encoded whole by the fast encoder inside Delta Tokenizer.

1 Introduction

A coding agent works in rounds. It sends the model a request, receives an answer, executes a tool, and comes back with the outcome so the model can take the next step in the same session. Every one of these requests repeats the conversation so far, although what is new is often no more than a tool's output or a one-line instruction [38, 40]. On the model side, this repetition is already handled. Serving engines keep the state of the shared prefix in the KV cache and run the model only over the text that was added [20, 43]. However, current tokenizers do not have such an equivalent mechanism. They treat each request as a fresh string and turn the full history back into token IDs on the CPU, turn after turn.

That repeated encoding has a real price, which also scales with the length of the context. Contexts are growing, and because the KV cache removes most of the model's own repeated work, the tokenizer's slice of each turn keeps widening. In a vLLM sweep of our own, the tokenizer's share of the time to first token (TTFT) rose from 10% to 64% as the prefix-cache hit rate approached 0.99. In our SGLang measurements, a Qwen3-8B chat turn whose 100K-token prefix is already cached reaches its first token after 145 ms, and 93–99 ms of that is the reference tokenizer running on a single CPU core ( §2.2.1§2.2.1). Making the tokenizer faster shrinks this step but leaves its shape intact: the work still repeats, and it still grows with the history.

Our core argument is that tokenization ought to be incremental, as the rest of the serving stack already is through its KV cache. A front end can hold on to the token sequence it produced for the previous turn and encode only the appended text plus the old suffix whose tokens the append might alter. What it must remember is modest, about one megabyte beyond the text the session stores anyway when it holds 100K tokens, four orders of magnitude and more below the KV cache the model keeps for those tokens. The model's cache cannot supply this reuse, since it is keyed by exactly the token IDs the tokenizer still has to compute.

However, incremental tokenization is more than concatenating the old IDs with the encoding of the new text, because adding characters to the last word can rewrite tokens that were

Figure

Figure 1. The four steps of the design: reuse across turns, parallel full encodes, scheduling at chunk granularity, and an adapter that plugs into an unmodified serving engine. C stands for a chunk and U for an update.

already produced. A request ending in pipe that receives line ends up with pipeline as its last token (Figure 4). Before byte-pair encoding (BPE) runs, the tokenizer also normalizes characters, matches special-token strings, and splits the text into pieces, and every one of these stages can shift a token boundary close to the append [12] (§2.2.4). An incorrect token sequence changes what the model receives and what its KV cache can hit, even when it decodes back to text that reads fine (§4.2). Reuse therefore needs an exact, guaranteed rule for where the old tokens cease to be valid, while a fixed overlap will not achieve it.

To address those fundamental challenges, this paper presents Delta Tokenizer, a CPU tokenization front end built on three ideas: exact incremental reuse, chunk-parallel encoding for the full encodes that remain, and a scheduler that fits short updates between chunks. When a session continues, Delta Tokenizer encodes only the new text along with a short stretch taken from the tail of the preceding request, finds where the new token sequence falls into agreement with the old one, and splices them at a boundary that the splitting rules of the tokenizer itself cannot move, and nowhere else. Should the window hold no such boundary, Delta Tokenizer enlarges it, and as a final fallback it encodes the append together with everything after the last boundary it has sealed.

Reuse does nothing for the full encodes that are still required. A session that has just started, or one whose history was edited, has to be encoded from the beginning. A long request of this kind, carrying no session state, can keep a tokenization worker busy for hundreds of milliseconds. Delta Tokenizer divides such a request into text chunks and encodes them in parallel across CPU cores. For BPE in general, this is unsafe. Where a token ends may hinge on text far away, so no cut position can be trusted without reading the entire input. Existing parallel tokenizers therefore cut at arbitrary positions and mend the seams using overlap plus retries, and LoPT, the most recent, is not exact in its published form [33]. What makes the problem tractable is that tokenizers in practice have more structure. A pre-tokenizer first breaks the text into short pieces, words and numbers for instance, and BPE never merges across two of them. Delta Tokenizer cuts only at positions where this split cannot move, which the characters on either side of the cut reveal, and it leaves special-token strings and Unicode normalization undisturbed across the cut. Each chunk is then encoded by an existing exact encoder on a core of its own, and concatenating the outputs yields the whole request's encoding, with nothing to reconcile at the seams and nothing to retry. Chunks have a target size, 64K characters unless configured otherwise (§3.4).

An incremental job is normally far smaller than one chunk. We propose tail-aware scheduling for those two types of jobs, such that an incremental job does not need to wait while long requests are being encoded chunk by chunk. Delta Tokenizer runs the tokenization cores as a worker pool, assigns every session a home worker that holds its reuse state, feeds chunks into a shared queue, and lets an incremental job slip in between chunks. A short update thus never queues behind an entire long stateless request. An adapter connects Delta Tokenizer to a serving engine like SGLang with no change to the engine itself. Figure 1 shows the four steps in sequence.

We evaluate Delta Tokenizer with six byte-level BPE tokenizers, among them the tokenizers of Qwen3 [29], gpt-oss [26], Llama-3.1 [22], and DeepSeek-V3 [7], across three CPU platforms, and with SGLang [43] serving Qwen3-8B and gpt-oss-120b, on web text, code, and multilingual text as well as public coding-agent transcripts [13] and agent trajectories [39] (§4). Measured against the Hugging Face reference tokenizer [12], which SGLang uses by default, incremental reuse brings a session turn from 93–99 ms down to about 2 ms, and the gain comes from the reuse rather than from the encoder. For chat requests with 100K-token contexts, the fast encoder in Delta Tokenizer, used without session state, is no quicker than the reference, whereas Delta Tokenizer cuts Qwen3-8B's median TTFT by 59%; fastokens [18], a backend that reuses earlier work as well, is as fast, but for 78 of the 279 raw-text requests its token IDs are wrong. On 16 cores, chunk-parallel encoding of a request of four million characters runs 8.2× faster than a serial encode and 1.6–2.1× faster than LoPT [33]. With the same FIFO queue and the same workers, scheduling chunks rather than whole requests takes the P99 latency for million-character requests down from 374 ms to 103 ms. Inside SGLang, agent sessions see their P99 TTFT fall from 995 ms to 105 ms when they produce 24 turns per second, and when long stateless requests that exceed the model's context tie up the front end, it goes from 1,441 ms to 63 ms, 23× lower. When documents of about 100K tokens are admitted instead and the model serves them from its prefix cache, the tail is still set by a stateless front end. The P99 TTFT of agent turns then drops from about half a second to under 70 ms, roughly 7×, and by about 20× once the server is limited to one core or runs a smaller model. Only when every long document is new does GPU prefill take over the tail, and the three front ends then land within 5% of one another.

The contributions of this paper are the following.

• Exact incremental tokenization ( §3.2§3.2). A front end that keeps the previous turn’s tokens and repairs only the tail, under a check, so the encoding work of a turn follows the size of the append instead of the size of the context. The check, rather than any fixed overlap, is what makes the reuse exact.

• Chunk-parallel full encoding at safe cuts ( §3.3§3.3). Practical tokenizers expose cut points that the surrounding characters identify. We use them to divide a long stateless request into independently encoded chunks whose concatenation is the reference output exactly, without the overlap, the seam matching, and the retries that earlier parallel tokenizers need.

• Tail-aware scheduling of updates and chunks ( §3.4§3.4). Chunk boundaries act as scheduling points inside a CPU pool that pins each session to a home worker and draws chunks from a shared queue, so a short incremental job can run in between one long request’s chunks.

• Integration and evaluation ( §4§4). We connect Delta Tokenizer to SGLang without modifying the engine and measure each mechanism on its own and in combination, including long documents that the model serves from its cache. Every comparison against the reference agrees, among them 41.8 billion documents encoded whole by Delta Tokenizer’s fast encoder.

References (35)