[mibz2 · Research blog](<https://lmmx.github.io/mibz2/blog/index.md>)

# Cutting repetitive text at its commonest three bytes

Jumping between occurrences of a block's commonest three-byte string spells repetitive data as fast as a grammar-built shortcut table, with no grammar to build.

2 December 2026 · 11 min read · [Research result](<#6-what-does-this-mean-for-the-decoder>)

Undoing bzip2's block sort means walking a permutation: each of a block's rows, up to 900 thousand of them, names the row that holds the next byte of the text, and a plain decoder visits them one at a time. mibz2's shipped decoder already skips most of that walk on repetitive data. Its Open kernel, described in [an earlier post](<https://lmmx.github.io/mibz2/blog/2026-11-19-open-returns/index.md>), keeps about a tenth of the rows and stores, for each kept row, its **return**: the next kept row the walk reaches and the bytes it spells on the way. Decoding then jumps from kept row to kept row, copying whole words.

Which rows to keep is a free choice, and it decides how long the words are and how often they repeat. This post reports what happens when the kept rows are chosen by content rather than by run length: keep exactly the rows whose text begins with the block's most frequent three-byte string. On 116 blocks of a Wikidata dump, held out from all tuning, the best prebuilt table of this kind spells the text in about a fifth of the time the shipped Open table takes on the same small virtual machine. It is also faster than the best table we have built with grammar compression, which our reference builders take eight to eleven times longer to construct. Three bytes is the only length that keeps the table both compact and made mostly of reused words. On ordinary prose, source code and JSON the idea fails completely, because almost every word occurs once, and a different kind of shortcut table, built from runs of rows, stops paying at almost the same point.

None of this is yet a faster decoder. The tables were built offline and timed on their own; building one inside the decoder and then using it still costs about twice the shipped decoder's total. [Section 1](<#1-what-does-cutting-at-a-string-mean>) works a small example by hand. [Section 2](<#2-how-fast-is-the-table>) gives the measurements and [section 3](<#3-why-three-bytes>) explains why three bytes wins. [Section 4](<#4-why-did-four-walks-at-once-slow-it-down>) covers a surprise in how the table behaves when four walks run at once, and [section 5](<#5-where-does-it-stop-working>) shows where the idea stops working. [Section 6](<#6-what-does-this-mean-for-the-decoder>) says what remains before the decoder can use it.

## 1\. What does cutting at a string mean?

Take the thirteen bytes `bananabandana`, the example the [Open post](<https://lmmx.github.io/mibz2/blog/2026-11-19-open-returns/index.md>) uses. bzip2 sorts its thirteen rotations; the rotation that starts at the beginning of the text lands in row 6. In a toy this small two bytes are enough to show the idea, so cut the text just before every occurrence of `an`. That gives five pieces, or **words**: `b`, `an`, `anab`, `and` and `ana`.

The rows that matter are the ones whose rotation begins with `an`, and here is the useful fact: because the rows are sorted, they sit next to each other. In this block they are rows 2 to 5, one contiguous range. Deciding whether a row is one of them takes two comparisons, and the whole set is described by two numbers. We add row 6, where the text starts, and call these rows the **anchors**.

Cutting bananabandana before every “an”

Conceptual example, worked by hand. The anchors (highlighted) are the rows whose rotation begins with the chosen string, which sorting places side by side, plus the row where the text starts. Decoding follows the table from the start row, copying one word per jump.

For each anchor the table records two things: which anchor the walk reaches next, and the word it spells on the way. Decoding starts at row 6, copies `b` and jumps to row 4, then copies `an` and jumps to row 3, and so on. Five jumps spell all thirteen bytes, where the plain walk takes thirteen single steps. In the language of the [Open post](<https://lmmx.github.io/mibz2/blog/2026-11-19-open-returns/index.md>), this is a **first-return map** on the anchors: each anchor's entry is where the walk first returns to the anchor set.

On a real block the anchors are the rows that begin with the block's most frequent three-byte string, found once per block. In Wikidata's JSON the commonest three-byte string recurs every 37 bytes on average, so the walk returns to an anchor often and the words between returns repeat. The table stores each distinct word's letters once, in a shared dictionary, and each anchor points into it.

The construction is chosen to compete with tables built by **grammar compression**, a family of methods that repeatedly replace the most frequent pair of symbols with a new symbol (the best known is RePair). Earlier work, summarised in [the Permutation Atlas post](<https://lmmx.github.io/mibz2/blog/2026-12-01-letting-go-3-the-shape-of-the-work/index.md>), used such grammars to choose the anchors and found tables whose words are long and well reused, but the grammar pass takes many seconds per hundred megabytes. Cutting at a fixed string needs no grammar at all: one pass to find the most frequent string, and the anchors follow.

## 2\. How fast is the table?

All the timings below measure only the step that uses a prebuilt table: following the jumps and copying the words, for the 116 held-out Wikidata blocks (104 MB of output), on one core of a small two-processor cloud virtual machine. Every table was checked byte for byte against mibz2's own decoder on every block. "Warm" means each block's table was already in the caches when timing began; "cold" means the caches had first been flushed. Each figure is the median of seven interleaved repeats.

The first measurement used the simplest layout: four bytes per anchor for the jump, and a dictionary of words. Times are in milliseconds, from the generic x86-64 build:

| Table, first run | Warm (ms) | Cold (ms) | Size (MB) | Offline build (s) |
| --- | ---: | ---: | ---: | ---: |
| Shipped Open table, four walks | 92.8 | 133.6 | 59.8 | 2.4 |
| Best grammar-built table, one walk | 31.8 | 52.0 | 51.1 | 18.2 |
| Cut at three bytes, one walk | 33.1 | 52.8 | 40.8 | 2.2 |

The simplest three-byte table matched the grammar table's speed in a fifth less memory. Its reference builder took about two seconds; the grammar's took fifteen to eighteen. Neither builder is the decoder's own, which builds the Open table far faster; section 6 returns to that cost.

A second run changed only how words are stored and copied: each word becomes a packed start and length, and words are copied in 32-byte pieces that the compiler turns into single wide vector moves, never a call to a general copy routine. The figure below is from that run, which timed the grammar table in its faster four-walk form.

Time to spell 116 Wikidata blocks from a prebuilt table (warm, one core)

Measured on a two-processor Haswell cloud virtual machine, one core, baseline x86-64 build, warm caches, median of seven repeats, all bars from one run. Only the step that consumes a prebuilt table is timed; building the table is not included. Sizes are the whole table in decimal megabytes for the 116 blocks.

With the packed layout, the three-byte table spelled the blocks in 21.1 milliseconds warm and 35.2 cold. The four-walk grammar table took 30.0 and 43.6, and the shipped Open table 94.5 and 132.9. The three-byte table is also the smallest of the three. The repeats did not overlap: the slowest three-byte repeat was faster than the fastest grammar repeat in all four combinations of warm or cold and of a generic or a processor-tuned build.

The two results have different statuses. The first table was registered in advance, with a written prediction and decision rule committed before any data. Its target was at most 0.65 times the shipped table's time, and it passed. The packed layout was a later variant, compared against the same packed layout copying in 16-byte pieces. Its registered rule asked for a table no larger as well as faster; the 32-byte copies need 16 more bytes of padding per block, so it failed that rule as written, and we report the speed as a measured finding beside that verdict.

## 3\. Why three bytes?

The length of the cutting string trades the number of jumps against how often each word is reused. A shorter string occurs more often, so there are more anchors and more jumps, each spelling a shorter word. A longer string occurs less often, so the words between occurrences grow longer and more of them are unique. A word that occurs once is not a shortcut at all: its letters sit in the dictionary exactly as they appear in the text, so the table merely holds a copy of that stretch of the output.

On the 116 blocks, cutting at two bytes makes 4.7 million jumps and a 39.0 MB table, and is the slowest of the three. Cutting at three bytes makes 2.8 million jumps; the words average 37 bytes and 17% of the output is spelled by words used once. Cutting at four bytes makes 1.9 million jumps and is a little faster still, but its table grows to 43.5 MB, and the share of the output held in single-use words jumps to 29%. The registration had fixed 25% as the point at which a table counts as mostly a copy of the text, and at four bytes the table passes it. Three bytes is the only length that is both compact and mostly made of reused words.

## 4\. Why did four walks at once slow it down?

The shipped Open table runs four independent walks through a block at once, interleaved in one loop, so that the processor can overlap their memory waits. Four walks speed up both the shipped table and the grammar table. They made the three-byte table take about half as long again.

The cause is the length of the words. The shipped table's words are short, 94% of them 16 bytes or fewer, so each copy is one small move. The three-byte table's words are long: 91% are longer than 16 bytes and 42% longer than 32. Copying four long words in one loop needs more registers than the processor has, and the compiled loop spends its time saving and restoring them on the stack; the four-walk loop had about five times as many such stack operations as the single walk. For the two-byte table, whose words are shorter, copying in 32-byte pieces fixed this, and four walks then ran 18% faster than one. For three bytes no layout we tried made four walks beat one, which is why the best result above is a single walk.

## 5\. Where does it stop working?

The same tables were built for three other corpora: Markdown documentation, Rust source code and JSON from a code repository. All 34 of their blocks are dense: their runs of equal bytes in the sorted last column are short. They have 0.28 to 0.37 runs per row, against 0.07 for Wikidata. The shipped decoder does not use Open on blocks like these.

On these corpora cutting at a common string produces almost nothing but single-use words. At two, three or four bytes, between 77% and 98% of each corpus's output was spelled by words that occur once, and the table was about as large as the text itself. Its consumer timings looked spectacular, forty to sixty-six times faster than the plain walk, but that speed only measures copying a stored transcript of the output. All twelve corpus-and-length combinations failed both of the registered tests for a real shortcut table.

A separate study met the same wall from another direction. The next-row map of a block is made of **bands**, ranges of consecutive rows that all move by the same amount, as [the slabs post](<https://lmmx.github.io/mibz2/blog/2026-12-02-cutting-the-bwt-into-cache-sized-slabs/index.md>) explains. A **move structure** stores one 16-byte record per band. After each jump the walk may land a few bands past the record it needs, so the structure splits a few long bands to guarantee it never has to step forward more than four records. On Wikidata it walked the whole text 2.1 times faster than mibz2's row-by-row walk (10.3 against 22.1 nanoseconds per byte), in 124 MB against the row table's 418 MB. On all three dense corpora it was larger than the row table and 1.3 to 1.5 times slower. The arithmetic explains the boundary: the plain walk stores four bytes per row, the move structure sixteen bytes per band, so it is smaller only while there are fewer than about a quarter as many bands as rows. After the extra bands that the splitting adds, that puts the crossover near 0.24 runs per row, between Wikidata and the dense corpora.

The same study also asked whether a learned-index approach, which replaces a table of band boundaries with a few straight-line segments plus a small correction, could find a row's band faster. We proved a tight bound on the number of segments needed and confirmed it exhaustively on small cases; on real blocks the segments compressed the boundary table 150 to 320 fold. But the extra levels of lookup made it 2 to 3 times slower than a plain directory indexed by the row's high bits, which in turn found a row's band 2 to 3 times faster than binary search.

Both families of shortcut, cutting at a string and storing bands, are therefore tools for repetitive data. They need long runs, which is exactly the regime where the shipped decoder already uses Open.

## 6\. What does this mean for the decoder?

The chain of the argument is short. Sorting puts every row that begins with a given string next to its neighbours, so a block's commonest three-byte string picks out one contiguous range of anchors at the cost of a single pass. On repetitive data the words between anchors are long and reused, so a table of jumps between them spells the text faster than both the shipped Open table and our best grammar-built table, while being smaller than either. Three bytes is the only length at which the words are both long and mostly reused, and on dense text no length works, because the words stop repeating.

What the decoder pays for is building the table as well as using it. Every timing above assumes the table already exists. Building it inside the decoder, from the data bzip2 actually stores, is a separate line of work: the builder must find the commonest string from the runs of the sorted last column, before any text exists. The first online builder that reproduces the three-byte table byte for byte took about 750 milliseconds for the 116 blocks, so that building and using it cost about three times the shipped decoder's total on the same machine. A second builder, which derives each anchor's next anchor and word by reasoning about the intervals of rows rather than by walking, cut that to about twice the shipped decoder's total. To break even, the builder still has to become roughly twice as fast again, with nothing lost in the step that uses the table.

That is the next question, and it is a well-posed one: an exact target with a measured consumer time, a single-pass way to choose the anchors, and a builder whose cost has already fallen by a third. The general lesson reaches beyond bzip2. In any sorted index, rows that share a prefix are contiguous, so a frequent prefix gives a cheap, exactly described set of landmarks, and the stretches between landmarks are as reusable as the data is repetitive.

---

**Sources:**

- The [first consumer measurement](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/products/2026-12-01-return-band-consumer-witness.md>) of three-byte and two-byte cut tables against grammar-built and shipped tables, with its pre-registered rules and raw data.
- The [diagnosis of the four-walk slowdown](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/products/2026-12-01-kgram-4lane-consumer-diagnosis.md>), with the word-length census and the stack-operation counts.
- The [packed-layout, string-length and cross-corpus study](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/products/2026-12-01-kgram-flat-frontier.md>), source of the figure in section 2 and the results of sections 3 and 5.
- The [band navigation study](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/products/2026-12-01-pla-band-navigation.md>): the move-structure crossover, the segment bound and the directory comparison.
- The online builders: the [first baseline](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/constructors/2026-12-01-top3gram-flat-c32-online-baseline.md>) and the [interval-based builder](<https://github.com/lmmx/mibz2/blob/439ad57c23f48fe1b99e4062ea6db47a9664c12a/frontier/atlas/constructors/2026-12-02-top3gram-v4-endpoint-induction.md>).
- The earlier posts on [Open's returns](<https://lmmx.github.io/mibz2/blog/2026-11-19-open-returns/index.md>), [the Permutation Atlas](<https://lmmx.github.io/mibz2/blog/2026-12-01-letting-go-3-the-shape-of-the-work/index.md>) and [cache-sized slabs](<https://lmmx.github.io/mibz2/blog/2026-12-02-cutting-the-bwt-into-cache-sized-slabs/index.md>).
