Manuscript Offprint

arXiv:2609.40016

Component-Weighted Centroid Search for Exact Incremental BPE

Harshit Verma, Rex Ying

Abstract

Exact incremental BPE maintains the canonical tokenization state after every appended byte. The recent algorithm of Jiang and Gong [2026] does this in O(log⁡2t)O(\log^2 t) worst-case time, where tt is the maximum canonical token length. Its centroid search visits O(log⁡t)O(\log t) components and can pay another O(log⁡t)O(\log t) for ordered point location at each one. Within Jiang and Gong's normalized/proper merge-stage model, we change only that local search. Each interval is weighted by the size of the recursive component it selects, so a move from size mm to size m′m' costs O(1+log⁡(m/m′))O(1 + \log(m/m')). These charges telescope, giving O(log⁡t)O(\log t) time per append and O(nlog⁡t)O(n \log t) over an nn-byte stream, with the same BPE semantics and asymptotic space. We also construct a normalized proper BPE family over a fixed alphabet where count-balanced search uses Θ(log⁡2t)\Theta(\log^2 t) probes on a reachable update, while the weighted search uses Θ(log⁡t)\Theta(\log t). A Rust implementation matches the predicted probe counts on every tested instance. On ordinary vocabularies the queried degrees are small, however, and the improvement is a worst-case guarantee rather than an average-speed result.

1 Introduction

Byte-pair encoding (BPE) is a standard subword layer in language-model pipelines [Sennrich et al., 2016]. Exact incremental tokenization is relevant when a serving session repeatedly appends bytes to a growing prompt or agent trace and needs tokenizer state without retokenizing the complete history. In the incremental version, the input arrives one byte at a time and the tokenizer must retain a last-token/backpointer state after every append. The full canonical tokenization of any prefix can then be recovered from that state. Jiang and Gong [2026] find the longest canonical suffix with augmented Aho–Corasick matching [Aho and Corasick, 1975] and search its suffix-successor tree using a centroid decomposition. Their bound has two logarithms:

O(log⁡t)⏟centroidlevels×O(log⁡t)⏟orderedbranchsearch\underbrace{O(\log t)}_{\mathrm{centroid levels}}\times\underbrace{O(\log t)}_{\mathrm{ordered branch search}}

The second logarithm comes from balancing each local search by the number of intervals. But the choices are not equally consequential: one interval may leave a large recursive component while the next leaves a single node. We instead weight an interval by the component left after choosing it. Large remaining subproblems are encountered early, and the cost of a choice is charged to the drop in component size. Matching, validity intervals, and the centroid decomposition are untouched.

There are two points to establish. First, the local charges really do telescope, including gaps and failed searches. Second, the bad count-balanced case must be possible for a normalized BPE dictionary and on an update the tokenizer can actually reach. We prove both and check the construction against an offline heap implementation.

Preprint.

Related work. Berglund and van der Merwe [2023] formalize canonical BPE, give a general local-update procedure, and show that dictionary-dependent finite lookahead suffices for left-to-right streaming; Cognetta and Okazaki [2025] further develop finite-state representations. Mamouras et al. [2026] derive bounded-delay streaming with input-independent memory, while TokTier repairs session appends with widening and fallback [Zhang and Cao, 2026]. These interfaces differ from retaining Jiang and Gong's exact state after every prefix; we improve that framework. Weight-sensitive and biased ordered search are classical [Mehlhorn, 1975]; our contribution is to weight each interval by its recursive CST component, so the local ratio charges telescope across the full centroid path. The lower bound concerns these two CST schemes, not every incremental tokenizer.

References (30)