Skip to content

perf(cache): take a word key in one load instead of a memcpy - #2276

Open
ArthurZucker wants to merge 1 commit into
feat/bpe-cache-minfrom
perf/word-key-fast
Open

perf(cache): take a word key in one load instead of a memcpy#2276
ArthurZucker wants to merge 1 commit into
feat/bpe-cache-minfrom
perf/word-key-fast

Conversation

@ArthurZucker

@ArthurZucker ArthurZucker commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Closes the TODO on pack_word.

pack_word built the key with lanes[..len].copy_from_slice(word). len is only
known at run time, so that is a call into memcpy behind a length branch that
mispredicts on nearly every short word. Read the 16 bytes at word.as_ptr() in one
unaligned load and mask the surplus off; the load reads past the word, so it is only
taken when all 16 bytes fall inside the page the word already sits in, and the old
copy stays as the fallback for the rest.

The packed u128 is byte-identical to before — same value, same length in the top
byte — so slot placement, tags and key comparison are unchanged. A new test asserts
both reads agree, including a word deliberately placed to straddle a page boundary.

Measured

Key construction timed on its own (spans from a pre-tokenizer pass over each corpus,
then key + hash per word), aarch64, lto = "fat". ns per word, so it is independent
of how the text was split:

corpus B/word copy_from_slice one load + mask
english 4.5 7.49 1.63 4.6×
french 5.0 7.78 2.01 3.9×
arabic 9.2 6.38 2.03 3.1×
russian 10.3 6.80 2.68 2.5×
chinese 13.7 4.23 2.05 2.1×

For scale: on english the old key path cost 1.59 ns/B against 0.48 ns/B for the whole
pre-tokenizer split, i.e. building the key cost more than 3× cutting the text into
words. It is now 0.36 ns/B.

Two variants I measured and did not ship:

  • crc32cd instead of aHash on the packed u128 — a further 1.7× on english
    (0.36 → 0.21 ns/B), but nothing on russian, and it needs a cfg fallback plus
    re-seeding to keep the table randomised. Happy to add it as a second commit if you
    want it.
  • Overlapping in-bounds loads instead of the page-guarded over-read (two 8-byte
    reads covering [0, len) exactly, no reading past the word). Byte-identical and
    needs no unsafe, but the 3-way length branch costs most of the win back:
    0.92 ns/B vs 0.36 on english.

vs #2267

Orthogonal, and they compose. #2267 changes where keys are computed (keyed spans
batched ahead of the model); this changes what one key costs, and does not touch the
pipeline. #2267 leaves pack_word as it was, so it inherits the same 4.6× if both land.

Worth noting for #2267's own question: in an A/B on this machine, computing the key
inside the split's emit walk was 7–22% slower than a separate pass over the emitted
spans on every corpus — the fused loop serialises open → key → next, where two loops
let the span array prefetch. That is the key-placement question only; it says nothing
about batching into tokenize_keyed_spans, which #2267's own harness measures (I could
not run it here, data/fixtures/ is empty locally).

PipelineTokenizer benchmark

9 / 10 models supported — PipelineTokenizer vs tokenizers v0.23.1 (latest release) · ~10 kB inputs · add_special_tokens on · single thread + 1/2/4/8/max-thread sweep

e38b966bc · 2026-08-04 04:18 UTC · Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz · 48 cores

Per-model encode throughput vs latest release

vs base branch (e87a72c56) — per-model geomean ×speedup of this PR's PipelineTokenizer against the base branch's; regressions in red.

Per-model encode throughput vs base branch

Per-model memory footprint

Minimal encode binary size

Decode

Round-trip: v0.23.1 encode_fast produces the id streams (same fixtures, add_special_tokens=true); both implementations decode those SAME ids with skip_special_tokens=false. MB/s counts decoded text bytes.

Per-model decode throughput vs latest release

Per-model decode memory footprint

bert-base-uncased — normalizer-heavy WordPiece · ×5.23 vs v0.23.1 · ×1.06 vs base · decode pending bert-base-uncased speedup bert-base-uncased stage decomposition bert-base-uncased thread scaling bert-base-uncased decode speedup bert-base-uncased decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 12+0 (peak 12) · Pipeline 8+2 (peak 17)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 7.0 26.9 ×3.86 ×0.97 3% (1.2) 76% (27.2) 14% (5.0) 8% (2.7) 0% (0.0) match
arb_Arab lang 4.2 26.6 ×6.36 ×1.08 3% (1.2) 76% (27.4) 10% (3.4) 10% (3.8) 0% (0.1) match
ben_Beng lang 6.0 37.7 ×6.26 ×1.09 5% (1.2) 75% (19.1) 12% (3.0) 9% (2.3) 0% (0.0) match
cmn_Hani lang 3.8 19.7 ×5.13 ×1.06 2% (1.2) 75% (37.5) 12% (6.0) 10% (4.9) 1% (0.6) match
ell_Grek lang 3.8 26.2 ×6.92 ×1.10 3% (1.2) 78% (28.6) 10% (3.5) 10% (3.6) 0% (0.0) match
eng_Latn lang 4.5 19.9 ×4.40 ×1.09 5% (2.5) 79% (38.6) 9% (4.4) 7% (3.5) 0% (0.0) match
heb_Hebr lang 4.2 20.8 ×4.93 ×1.05 2% (1.2) 80% (37.1) 8% (3.7) 10% (4.5) 0% (0.0) match
hin_Deva lang 6.5 28.7 ×4.40 ×1.05 3% (1.2) 80% (27.0) 10% (3.3) 7% (2.3) 0% (0.1) match
jpn_Jpan lang 4.3 28.7 ×6.72 ×1.06 4% (1.2) 70% (23.3) 14% (4.7) 12% (4.0) 0% (0.1) match
kat_Geor lang 6.2 29.5 ×4.78 ×1.05 3% (1.2) 79% (26.2) 11% (3.5) 8% (2.5) 0% (0.0) match
kor_Hang lang 2.4 19.5 ×8.03 ×1.11 2% (1.2) 71% (35.0) 15% (7.4) 11% (5.4) 1% (0.5) match
rus_Cyrl lang 3.7 27.0 ×7.38 ×1.14 3% (1.2) 78% (27.4) 9% (3.2) 10% (3.4) 0% (0.0) match
tam_Taml lang 7.0 40.4 ×5.76 ×1.05 5% (1.2) 77% (18.6) 11% (2.6) 7% (1.8) 0% (0.0) match
tha_Thai lang 8.4 33.5 ×3.97 ×1.01 4% (1.2) 86% (25.4) 6% (1.8) 3% (1.0) 0% (0.0) match
added_normalized_dense modalities 6.8 19.9 ×2.95 ×1.02 3% (1.3) 81% (40.4) 16% (7.8) 0% (0.0) 1% (0.4) match
added_normalized_sparse modalities 5.3 19.4 ×3.63 ×1.06 4% (1.9) 79% (40.0) 13% (6.7) 4% (2.2) 0% (0.0) match
added_special_dense modalities 5.3 40.1 ×7.54 ×1.05 21% (5.1) 39% (9.3) 36% (8.6) 3% (0.8) 0% (0.0) match
added_special_sparse modalities 4.0 22.9 ×5.72 ×1.08 8% (3.5) 66% (28.2) 19% (8.1) 7% (2.8) 0% (0.0) match
agentic-traces modalities 3.9 19.5 ×5.01 ×1.09 5% (2.3) 76% (38.4) 10% (4.9) 10% (4.8) 0% (0.0) match
agentic_swe modalities 4.1 20.2 ×4.92 ×1.05 4% (1.9) 80% (38.5) 8% (3.6) 9% (4.3) 0% (0.0) match
code_mixed modalities 4.0 20.2 ×5.09 ×1.07 4% (2.1) 78% (38.3) 9% (4.2) 9% (4.2) 0% (0.0) match
math_latex modalities 4.0 19.6 ×4.85 ×1.09 5% (2.5) 77% (38.4) 9% (4.6) 9% (4.4) 0% (0.0) match
deepseek-v4 — deepseek 3-regex split-heavy byte-level BPE · ×25.28 vs v0.23.1 · ×6.41 vs base · decode pending deepseek-v4 speedup deepseek-v4 stage decomposition deepseek-v4 thread scaling deepseek-v4 decode speedup deepseek-v4 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 62+0 (peak 67) · Pipeline 82+0 (peak 82)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 4.3 94.7 ×21.78 ×2.85 7% (0.7) 0% (0.0) 52% (4.7) 40% (3.7) 1% (0.1) match
arb_Arab lang 4.3 115.8 ×26.79 ×7.16 8% (0.6) 0% (0.0) 46% (3.4) 46% (3.4) 0% (0.0) match
ben_Beng lang 6.3 141.8 ×22.41 ×8.20 10% (0.6) 0% (0.0) 52% (3.2) 38% (2.4) 0% (0.0) match
cmn_Hani lang 3.8 117.0 ×30.90 ×7.71 11% (0.8) 0% (0.0) 45% (3.2) 43% (3.0) 1% (0.1) match
ell_Grek lang 4.7 119.6 ×25.39 ×6.88 8% (0.6) 0% (0.0) 48% (3.5) 43% (3.1) 1% (0.1) match
eng_Latn lang 3.2 83.7 ×26.14 ×6.74 18% (1.9) 0% (0.0) 47% (5.1) 35% (3.7) 0% (0.0) match
heb_Hebr lang 4.1 110.5 ×27.11 ×8.53 8% (0.6) 0% (0.0) 45% (3.6) 47% (3.7) 1% (0.0) match
hin_Deva lang 5.9 131.1 ×22.17 ×6.28 9% (0.6) 0% (0.0) 50% (3.4) 41% (2.8) 0% (0.0) match
jpn_Jpan lang 4.4 136.5 ×31.23 ×7.91 11% (0.7) 0% (0.0) 51% (3.0) 38% (2.2) 0% (0.0) match
kat_Geor lang 6.0 144.3 ×23.95 ×8.63 10% (0.6) 0% (0.0) 51% (3.0) 39% (2.3) 0% (0.0) match
kor_Hang lang 3.7 90.6 ×24.67 ×4.70 7% (0.6) 0% (0.0) 40% (3.7) 53% (4.9) 0% (0.0) match
rus_Cyrl lang 4.5 127.1 ×27.99 ×8.92 9% (0.6) 0% (0.0) 49% (3.4) 42% (2.9) 0% (0.0) match
tam_Taml lang 6.3 169.9 ×26.85 ×9.84 11% (0.6) 0% (0.0) 51% (2.8) 38% (2.0) 0% (0.0) match
tha_Thai lang 7.2 222.9 ×30.95 ×15.93 15% (0.6) 0% (0.0) 59% (2.3) 26% (1.0) 0% (0.0) match
added_normalized_dense modalities 6.1 156.8 ×25.67 ×7.04 13% (0.7) 0% (0.0) 46% (2.8) 42% (2.5) 0% (0.0) match
added_normalized_sparse modalities 5.4 121.4 ×22.65 ×6.49 16% (1.3) 0% (0.0) 49% (3.8) 36% (2.8) 0% (0.0) match
added_special_dense modalities 3.7 62.2 ×16.98 ×1.76 42% (6.5) 3% (0.4) 37% (5.7) 16% (2.5) 2% (0.3) match
added_special_sparse modalities 4.1 68.9 ×16.94 ×3.43 29% (3.9) 1% (0.2) 47% (6.3) 24% (3.3) 0% (0.0) match
agentic-traces modalities 3.0 80.0 ×26.25 ×5.69 15% (1.8) 0% (0.0) 46% (5.4) 38% (4.4) 1% (0.1) match
agentic_swe modalities 3.0 100.0 ×32.88 ×6.93 14% (1.3) 0% (0.0) 42% (3.8) 44% (4.0) 0% (0.0) match
code_mixed modalities 3.5 91.0 ×25.83 ×6.05 15% (1.5) 0% (0.0) 45% (4.6) 39% (4.0) 1% (0.1) match
math_latex modalities 2.9 80.9 ×28.21 ×5.93 17% (1.9) 0% (0.0) 47% (5.3) 36% (4.1) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.62 3.49 4.72 5.59 43.0 20.3 9.1 9.1× / 7.7× 4.3× / 3.6× 1.9× / 1.6×
arb_Arab 1.00 2.96 3.44 5.41 48.6 22.5 10.1 14.1× / 9.0× 6.5× / 4.2× 2.9× / 1.9×
ben_Beng 1.46 2.95 3.20 4.69 36.7 16.0 7.5 11.5× / 7.8× 5.0× / 3.4× 2.4× / 1.6×
cmn_Hani 1.13 2.38 3.15 4.40 60.3 33.5 14.1 19.1× / 13.7× 10.6× / 7.6× 4.5× / 3.2×
ell_Grek 0.58 3.06 3.47 5.95 48.1 20.8 9.6 13.9× / 8.1× 6.0× / 3.5× 2.8× / 1.6×
eng_Latn 0.09 1.74 5.06 6.71 64.3 39.6 16.0 12.7× / 9.6× 7.8× / 5.9× 3.2× / 2.4×
heb_Hebr 1.00 3.05 3.60 5.65 52.0 23.9 10.6 14.5× / 9.2× 6.6× / 4.2× 3.0× / 1.9×
hin_Deva 1.36 3.11 3.40 5.15 37.7 18.2 8.5 11.1× / 7.3× 5.4× / 3.5× 2.5× / 1.6×
jpn_Jpan 1.56 3.47 2.99 4.90 54.7 27.4 11.8 18.3× / 11.2× 9.2× / 5.6× 3.9× / 2.4×
kat_Geor 1.38 2.52 2.98 4.12 32.1 15.1 7.2 10.8× / 7.8× 5.1× / 3.7× 2.4× / 1.7×
kor_Hang 1.08 2.85 3.72 5.49 51.6 27.2 11.7 13.9× / 9.4× 7.3× / 4.9× 3.2× / 2.1×
rus_Cyrl 1.02 2.97 3.36 5.30 46.9 20.4 9.4 14.0× / 8.8× 6.1× / 3.8× 2.8× / 1.8×
tam_Taml 0.92 3.00 2.76 4.84 32.5 13.4 6.5 11.8× / 6.7× 4.9× / 2.8× 2.3× / 1.3×
tha_Thai 1.37 2.58 2.33 3.54 26.7 10.1 5.2 11.5× / 7.5× 4.3× / 2.9× 2.2× / 1.5×
added_normalized_dense 0.06 1.77 2.76 4.47 42.9 19.7 9.1 15.5× / 9.6× 7.1× / 4.4× 3.3× / 2.0×
added_normalized_sparse 0.06 1.77 3.80 5.51 48.0 25.3 11.3 12.6× / 8.7× 6.7× / 4.6× 3.0× / 2.0×
added_special_dense 0.06 1.77 5.69 7.40 181.7 97.0 39.0 31.9× / 24.5× 17.0× / 13.1× 6.8× / 5.3×
added_special_sparse 0.06 1.77 6.35 8.06 100.4 57.5 23.7 15.8× / 12.5× 9.1× / 7.1× 3.7× / 2.9×
agentic-traces 0.57 1.77 5.38 6.58 83.6 51.5 19.9 15.5× / 12.7× 9.6× / 7.8× 3.7× / 3.0×
agentic_swe 0.51 1.74 3.85 5.08 93.5 64.4 23.6 24.3× / 18.4× 16.7× / 12.7× 6.1× / 4.6×
code_mixed 0.08 1.74 4.61 6.28 76.3 52.6 18.3 16.5× / 12.1× 11.4× / 8.4× 4.0× / 2.9×
math_latex 0.57 1.78 5.34 6.55 76.8 48.4 19.1 14.4× / 11.7× 9.1× / 7.4× 3.6× / 2.9×
gemma-4 — byte-fallback BPE, Metaspace-style split (gemma-4) · ×2.10 vs v0.23.1 · ×1.17 vs base · decode pending gemma-4 speedup gemma-4 stage decomposition gemma-4 thread scaling gemma-4 decode speedup gemma-4 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 304+0 (peak 371) · Pipeline 275+0 (peak 371)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 10.8 28.3 ×2.63 ×1.03 2% (0.7) 6% (2.2) 0% (0.0) 92% (31.4) 0% (0.0) match
arb_Arab lang 7.5 13.8 ×1.83 ×1.04 1% (0.6) 4% (2.6) 0% (0.0) 96% (67.1) 0% (0.0) match
ben_Beng lang 10.8 19.6 ×1.82 ×1.08 1% (0.6) 3% (1.7) 0% (0.0) 96% (49.1) 0% (0.0) match
cmn_Hani lang 13.1 36.2 ×2.75 ×1.07 2% (0.6) 1% (0.3) 0% (0.0) 97% (24.6) 0% (0.0) match
ell_Grek lang 7.9 15.6 ×1.96 ×1.05 1% (0.6) 4% (2.6) 0% (0.0) 95% (59.6) 0% (0.0) match
eng_Latn lang 4.0 5.8 ×1.44 ×1.08 1% (2.0) 3% (4.8) 0% (0.0) 96% (163.6) 0% (0.0) match
heb_Hebr lang 8.2 17.4 ×2.11 ×1.04 1% (0.6) 5% (2.7) 0% (0.0) 94% (52.5) 0% (0.0) match
hin_Deva lang 10.1 19.0 ×1.87 ×1.08 1% (0.6) 5% (2.3) 0% (0.0) 94% (48.8) 0% (0.0) match
jpn_Jpan lang 13.7 31.2 ×2.28 ×1.08 2% (0.6) 1% (0.2) 0% (0.0) 97% (30.3) 1% (0.2) match
kat_Geor lang 12.3 25.5 ×2.07 ×1.04 2% (0.6) 4% (1.5) 0% (0.0) 94% (36.6) 0% (0.1) match
kor_Hang lang 10.2 27.2 ×2.66 ×1.08 2% (0.6) 8% (2.7) 0% (0.0) 91% (32.2) 0% (0.0) match
rus_Cyrl lang 7.4 11.4 ×1.55 ×1.07 1% (0.6) 3% (2.3) 0% (0.0) 99% (82.5) 0% (0.0) match
tam_Taml lang 11.6 20.7 ×1.78 ×1.06 1% (0.6) 3% (1.3) 0% (0.0) 96% (46.2) 0% (0.0) match
tha_Thai lang 13.1 25.0 ×1.90 ×1.05 2% (0.6) 2% (0.7) 0% (0.0) 97% (37.0) 0% (0.0) match
added_normalized_dense modalities 5.2 7.7 ×1.47 ×1.06 1% (0.7) 2% (2.9) 0% (0.1) 97% (127.1) 0% (0.2) match
added_normalized_sparse modalities 4.7 6.8 ×1.45 ×1.07 1% (1.4) 3% (4.5) 0% (0.0) 96% (141.4) 0% (0.0) match
added_special_dense modalities 4.7 34.5 ×7.28 ×1.69 35% (9.4) 32% (8.6) 25% (6.7) 10% (2.7) 0% (0.0) match
added_special_sparse modalities 7.3 48.8 ×6.72 ×4.98 26% (5.2) 43% (8.5) 24% (4.9) 7% (1.4) 0% (0.0) match
agentic-traces modalities 4.3 6.6 ×1.53 ×1.09 1% (1.8) 3% (4.6) 0% (0.0) 96% (141.6) 0% (0.3) match
agentic_swe modalities 4.1 7.2 ×1.77 ×1.07 1% (1.3) 6% (7.6) 0% (0.0) 94% (128.0) 0% (0.0) match
code_mixed modalities 4.3 6.9 ×1.61 ×1.07 1% (1.6) 4% (6.2) 0% (0.0) 94% (137.3) 1% (1.0) match
math_latex modalities 4.2 6.2 ×1.49 ×1.07 1% (1.9) 3% (4.6) 0% (0.0) 96% (151.6) 0% (0.3) match
gpt2 — gpt2 ByteLevel regex · ×30.08 vs v0.23.1 · ×3.82 vs base · decode pending gpt2 speedup gpt2 stage decomposition gpt2 thread scaling gpt2 decode speedup gpt2 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 25+2 (peak 27) · Pipeline 27+0 (peak 27)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 3.8 95.7 ×25.15 ×2.34 8% (0.7) 0% (0.0) 47% (3.6) 45% (3.5) 0% (0.0) match
arb_Arab lang 3.7 110.7 ×30.15 ×4.33 8% (0.6) 0% (0.0) 31% (2.3) 60% (4.3) 0% (0.0) match
ben_Beng lang 2.8 91.5 ×32.68 ×2.01 6% (0.6) 0% (0.0) 31% (3.0) 62% (6.1) 1% (0.1) match
cmn_Hani lang 3.7 118.6 ×32.15 ×4.29 10% (0.6) 0% (0.0) 37% (2.3) 54% (3.4) 0% (0.0) match
ell_Grek lang 4.2 123.1 ×29.23 ×4.34 9% (0.6) 0% (0.0) 32% (2.2) 58% (3.9) 0% (0.0) match
eng_Latn lang 3.4 101.9 ×29.86 ×7.49 23% (2.0) 0% (0.0) 33% (2.9) 44% (3.8) 0% (0.0) match
heb_Hebr lang 3.8 115.6 ×30.11 ×4.01 8% (0.6) 0% (0.0) 31% (2.3) 61% (4.5) 0% (0.0) match
hin_Deva lang 2.9 105.2 ×35.74 ×2.83 7% (0.6) 0% (0.0) 35% (3.1) 59% (5.2) 0% (0.0) match
jpn_Jpan lang 4.4 154.7 ×35.39 ×7.31 12% (0.6) 0% (0.0) 41% (2.1) 48% (2.5) 0% (0.0) match
kat_Geor lang 4.6 154.3 ×33.52 ×2.13 11% (0.6) 0% (0.0) 40% (2.1) 49% (2.5) 0% (0.0) match
kor_Hang lang 3.2 98.1 ×30.20 ×2.19 7% (0.6) 0% (0.0) 29% (2.4) 64% (5.5) 0% (0.0) match
rus_Cyrl lang 4.1 126.8 ×30.78 ×4.65 9% (0.6) 0% (0.0) 33% (2.1) 58% (3.8) 0% (0.0) match
tam_Taml lang 2.6 103.9 ×39.75 ×1.39 7% (0.6) 0% (0.0) 30% (2.7) 63% (5.7) 0% (0.0) match
tha_Thai lang 3.5 113.3 ×31.94 ×3.15 8% (0.6) 0% (0.0) 34% (2.5) 57% (4.2) 0% (0.0) match
added_normalized_dense modalities 5.8 193.5 ×33.61 ×7.99 16% (0.7) 0% (0.0) 24% (1.1) 59% (2.7) 2% (0.1) match
added_normalized_sparse modalities 4.9 146.8 ×29.79 ×7.05 20% (1.2) 0% (0.0) 30% (1.9) 47% (3.0) 4% (0.3) match
added_special_dense modalities 4.1 81.3 ×19.88 ×1.77 43% (4.9) 1% (0.1) 36% (4.2) 20% (2.3) 1% (0.1) match
added_special_sparse modalities 4.2 82.1 ×19.72 ×3.65 28% (3.1) 0% (0.0) 41% (4.6) 30% (3.4) 1% (0.1) match
agentic-traces modalities 3.1 90.3 ×29.31 ×5.61 17% (1.8) 0% (0.0) 34% (3.4) 48% (4.9) 0% (0.0) match
agentic_swe modalities 3.4 106.0 ×31.61 ×4.32 15% (1.3) 0% (0.0) 28% (2.4) 57% (4.8) 0% (0.0) match
code_mixed modalities 3.4 99.6 ×28.96 ×4.87 17% (1.5) 0% (0.0) 31% (2.9) 54% (5.0) 0% (0.0) match
math_latex modalities 3.2 97.7 ×30.23 ×6.50 20% (1.9) 0% (0.0) 34% (3.2) 46% (4.3) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.63 3.48 3.65 4.50 26.3 20.7 5.8 4.8 7.2× / 5.8× 5.7× / 4.6× 1.6× / 1.3× 1.3× / 1.1×
arb_Arab 1.00 3.04 2.27 4.31 30.6 25.8 6.8 5.3 13.5× / 7.1× 11.4× / 6.0× 3.0× / 1.6× 2.3× / 1.2×
ben_Beng 1.46 2.94 3.03 4.51 62.7 56.7 13.8 4.1 20.7× / 13.9× 18.7× / 12.6× 4.6× / 3.1× 1.3× / 0.9×
cmn_Hani 1.12 2.35 2.33 3.55 25.3 21.1 6.0 2.4 10.9× / 7.1× 9.1× / 5.9× 2.6× / 1.7× 1.0× / 0.7×
ell_Grek 0.58 3.03 2.16 4.61 27.1 21.9 5.9 4.7 12.5× / 5.9× 10.1× / 4.8× 2.7× / 1.3× 2.2× / 1.0×
eng_Latn 0.10 1.74 2.87 4.52 41.4 41.6 11.9 3.9 14.4× / 9.2× 14.5× / 9.2× 4.2× / 2.6× 1.4× / 0.9×
heb_Hebr 0.99 3.09 2.29 4.39 29.7 25.8 6.9 3.1 13.0× / 6.8× 11.2× / 5.9× 3.0× / 1.6× 1.4× / 0.7×
hin_Deva 1.36 3.19 3.09 4.92 57.8 53.2 13.6 4.3 18.7× / 11.8× 17.2× / 10.8× 4.4× / 2.8× 1.4× / 0.9×
jpn_Jpan 1.56 3.51 2.12 4.07 22.9 17.5 5.0 3.9 10.8× / 5.6× 8.3× / 4.3× 2.4× / 1.2× 1.8× / 1.0×
kat_Geor 1.39 2.59 2.06 3.25 16.6 14.2 4.2 2.0 8.1× / 5.1× 6.9× / 4.4× 2.0× / 1.3× 1.0× / 0.6×
kor_Hang 1.08 2.80 2.43 4.15 30.2 28.0 7.4 3.7 12.5× / 7.3× 11.6× / 6.8× 3.1× / 1.8× 1.5× / 0.9×
rus_Cyrl 1.03 2.96 2.12 4.05 26.1 21.1 5.8 2.4 12.3× / 6.4× 10.0× / 5.2× 2.7× / 1.4× 1.2× / 0.6×
tam_Taml 0.92 3.01 2.69 4.78 65.9 58.6 14.2 3.8 24.5× / 13.8× 21.7× / 12.3× 5.3× / 3.0× 1.4× / 0.8×
tha_Thai 1.36 2.61 2.51 3.76 38.1 31.5 8.7 3.2 15.2× / 10.1× 12.6× / 8.4× 3.5× / 2.3× 1.3× / 0.9×
added_normalized_dense 0.06 1.77 1.07 2.78 21.9 22.7 6.5 2.0 20.5× / 7.9× 21.2× / 8.2× 6.0× / 2.3× 1.9× / 0.7×
added_normalized_sparse 0.06 1.77 1.94 3.65 29.4 30.7 8.6 2.8 15.2× / 8.1× 15.8× / 8.4× 4.4× / 2.3× 1.5× / 0.8×
added_special_dense 0.06 1.77 4.21 5.91 88.5 94.1 20.4 3.1 21.0× / 15.0× 22.4× / 15.9× 4.9× / 3.5× 0.7× / 0.5×
added_special_sparse 0.06 1.77 4.55 6.26 57.3 61.5 14.7 3.6 12.6× / 9.2× 13.5× / 9.8× 3.2× / 2.3× 0.8× / 0.6×
agentic-traces 0.57 1.78 3.41 4.62 54.8 59.7 15.4 4.9 16.1× / 11.9× 17.5× / 12.9× 4.5× / 3.3× 1.4× / 1.1×
agentic_swe 0.52 1.76 2.37 3.61 55.8 67.3 14.6 3.7 23.6× / 15.5× 28.4× / 18.7× 6.2× / 4.1× 1.6× / 1.0×
code_mixed 0.08 1.72 2.85 4.49 54.5 65.8 15.3 4.2 19.1× / 12.1× 23.1× / 14.7× 5.4× / 3.4× 1.5× / 0.9×
math_latex 0.56 1.78 3.20 4.43 49.1 50.9 14.3 4.5 15.3× / 11.1× 15.9× / 11.5× 4.5× / 3.2× 1.4× / 1.0×
gpt-oss — o200k-regex byte-level BPE (gpt-oss) · ×23.22 vs v0.23.1 · ×5.12 vs base · decode pending gpt-oss speedup gpt-oss stage decomposition gpt-oss thread scaling gpt-oss decode speedup gpt-oss decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 241+0 (peak 315) · Pipeline 234+0 (peak 316)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 4.2 97.3 ×23.12 ×4.26 7% (0.7) 0% (0.0) 53% (4.8) 40% (3.5) 0% (0.0) match
arb_Arab lang 4.9 131.2 ×26.84 ×7.36 9% (0.6) 0% (0.0) 46% (3.3) 45% (3.1) 0% (0.0) match
ben_Beng lang 7.1 141.8 ×19.87 ×8.44 9% (0.6) 0% (0.0) 56% (3.7) 35% (2.3) 0% (0.0) match
cmn_Hani lang 4.9 133.2 ×27.42 ×11.42 9% (0.6) 0% (0.0) 50% (3.3) 40% (2.7) 1% (0.1) match
ell_Grek lang 5.2 133.6 ×25.62 ×8.48 9% (0.6) 0% (0.0) 48% (3.2) 43% (2.9) 0% (0.0) match
eng_Latn lang 4.2 91.1 ×21.90 ×2.26 19% (1.9) 0% (0.0) 44% (4.6) 36% (3.7) 0% (0.0) match
heb_Hebr lang 4.9 126.3 ×25.95 ×7.74 8% (0.6) 0% (0.0) 45% (3.3) 47% (3.5) 0% (0.0) match
hin_Deva lang 7.2 140.4 ×19.46 ×5.33 9% (0.6) 0% (0.0) 57% (3.8) 34% (2.3) 0% (0.0) match
jpn_Jpan lang 5.7 160.5 ×28.32 ×12.97 11% (0.6) 0% (0.0) 54% (3.1) 35% (2.0) 0% (0.0) match
kat_Geor lang 7.0 164.0 ×23.39 ×11.91 10% (0.6) 0% (0.0) 52% (2.9) 38% (2.1) 0% (0.0) match
kor_Hang lang 4.2 95.8 ×22.97 ×6.48 6% (0.6) 0% (0.0) 39% (3.7) 54% (5.1) 0% (0.0) match
rus_Cyrl lang 5.3 134.6 ×25.29 ×9.08 9% (0.6) 0% (0.0) 48% (3.1) 43% (2.8) 0% (0.0) match
tam_Taml lang 7.2 158.2 ×21.98 ×12.35 10% (0.6) 0% (0.0) 56% (3.2) 34% (1.9) 0% (0.0) match
tha_Thai lang 8.0 176.2 ×22.08 ×15.91 12% (0.6) 0% (0.0) 65% (3.2) 21% (1.0) 1% (0.1) match
added_normalized_dense modalities 5.9 168.2 ×28.71 ×7.02 13% (0.7) 0% (0.0) 40% (2.2) 47% (2.6) 0% (0.0) match
added_normalized_sparse modalities 5.6 130.9 ×23.23 ×3.27 18% (1.3) 0% (0.0) 44% (3.2) 36% (2.6) 2% (0.1) match
added_special_dense modalities 4.5 73.9 ×16.34 ×1.00 38% (4.9) 1% (0.1) 41% (5.2) 19% (2.4) 1% (0.2) match
added_special_sparse modalities 4.5 76.6 ×17.18 ×1.02 26% (3.1) 0% (0.0) 49% (6.0) 24% (2.9) 1% (0.1) match
agentic-traces modalities 3.7 85.4 ×23.33 ×2.32 16% (1.7) 0% (0.0) 45% (4.9) 39% (4.2) 0% (0.0) match
agentic_swe modalities 4.0 102.7 ×25.58 ×3.83 14% (1.3) 0% (0.0) 41% (3.7) 44% (4.0) 0% (0.0) match
code_mixed modalities 4.0 95.8 ×23.81 ×1.98 16% (1.5) 0% (0.0) 45% (4.3) 39% (3.8) 0% (0.0) match
math_latex modalities 3.6 84.2 ×23.53 ×2.29 17% (1.9) 0% (0.0) 44% (4.8) 38% (4.2) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.62 3.55 4.76 5.69 29.5 14.3 7.0 4.8 6.2× / 5.2× 3.0× / 2.5× 1.5× / 1.2× 1.0× / 0.8×
arb_Arab 1.01 3.01 3.27 5.27 33.6 15.8 7.6 5.0 10.3× / 6.4× 4.8× / 3.0× 2.3× / 1.4× 1.5× / 1.0×
ben_Beng 1.45 3.00 3.68 5.22 23.5 10.9 5.4 2.8 6.4× / 4.5× 3.0× / 2.1× 1.5× / 1.0× 0.8× / 0.5×
cmn_Hani 1.13 2.40 3.33 4.60 21.6 10.8 5.4 2.4 6.5× / 4.7× 3.3× / 2.4× 1.6× / 1.2× 0.7× / 0.5×
ell_Grek 0.58 3.00 3.23 5.65 29.7 15.0 6.9 5.0 9.2× / 5.3× 4.6× / 2.6× 2.1× / 1.2× 1.6× / 0.9×
eng_Latn 0.10 1.74 4.55 6.19 42.4 29.2 13.8 4.1 9.3× / 6.8× 6.4× / 4.7× 3.0× / 2.2× 0.9× / 0.7×
heb_Hebr 1.05 3.06 3.35 5.36 33.2 17.6 8.0 2.9 9.9× / 6.2× 5.3× / 3.3× 2.4× / 1.5× 0.9× / 0.5×
hin_Deva 1.36 3.12 3.80 5.56 25.7 12.7 6.4 3.1 6.8× / 4.6× 3.4× / 2.3× 1.7× / 1.1× 0.8× / 0.6×
jpn_Jpan 1.56 3.45 3.09 4.99 20.2 9.1 4.7 3.7 6.5× / 4.1× 2.9× / 1.8× 1.5× / 1.0× 1.2× / 0.7×
kat_Geor 1.39 2.50 2.94 4.05 19.0 10.1 4.6 2.1 6.4× / 4.7× 3.4× / 2.5× 1.6× / 1.1× 0.7× / 0.5×
kor_Hang 1.08 2.89 3.72 5.53 33.3 19.7 8.9 3.7 8.9× / 6.0× 5.3× / 3.6× 2.4× / 1.6× 1.0× / 0.7×
rus_Cyrl 1.03 2.96 3.15 5.07 28.4 14.8 6.7 4.8 9.0× / 5.6× 4.7× / 2.9× 2.1× / 1.3× 1.5× / 0.9×
tam_Taml 0.93 2.95 3.22 5.25 19.0 8.7 4.3 3.1 5.9× / 3.6× 2.7× / 1.7× 1.3× / 0.8× 1.0× / 0.6×
tha_Thai 1.37 2.59 3.19 4.42 13.2 5.7 2.8 2.2 4.1× / 3.0× 1.8× / 1.3× 0.9× / 0.6× 0.7× / 0.5×
added_normalized_dense 0.06 1.77 2.21 3.92 32.0 17.0 11.2 2.0 14.5× / 8.2× 7.7× / 4.3× 5.1× / 2.9× 0.9× / 0.5×
added_normalized_sparse 0.06 1.77 3.20 4.90 34.6 20.5 11.8 2.9 10.8× / 7.1× 6.4× / 4.2× 3.7× / 2.4× 0.9× / 0.6×
added_special_dense 0.06 1.77 5.22 6.92 82.4 67.7 24.0 3.3 15.8× / 11.9× 13.0× / 9.8× 4.6× / 3.5× 0.6× / 0.5×
added_special_sparse 0.12 1.77 6.01 7.65 55.2 41.5 17.0 3.6 9.2× / 7.2× 6.9× / 5.4× 2.8× / 2.2× 0.6× / 0.5×
agentic-traces 0.57 1.75 4.94 6.13 50.9 41.0 17.2 4.8 10.3× / 8.3× 8.3× / 6.7× 3.5× / 2.8× 1.0× / 0.8×
agentic_swe 0.66 1.73 3.68 4.76 51.2 48.3 17.3 3.5 13.9× / 10.8× 13.1× / 10.2× 4.7× / 3.6× 1.0× / 0.7×
code_mixed 0.07 1.73 4.35 6.01 50.7 47.5 17.2 4.2 11.7× / 8.4× 10.9× / 7.9× 4.0× / 2.9× 1.0× / 0.7×
math_latex 0.57 1.78 4.83 6.04 48.5 35.4 15.9 4.5 10.1× / 8.0× 7.3× / 5.9× 3.3× / 2.6× 0.9× / 0.7×
glm-5.2 — cl100k-variant regex byte-level BPE (glm-5.2) · ×23.81 vs v0.23.1 · ×3.91 vs base · decode pending glm-5.2 speedup glm-5.2 stage decomposition glm-5.2 thread scaling glm-5.2 decode speedup glm-5.2 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 169+0 (peak 230) · Pipeline 170+0 (peak 231)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 4.3 99.6 ×23.25 ×2.21 15% (1.2) 0% (0.0) 44% (3.7) 41% (3.5) 0% (0.0) match
arb_Arab lang 4.8 124.0 ×25.72 ×7.28 17% (1.2) 0% (0.0) 33% (2.3) 51% (3.6) 0% (0.0) match
ben_Beng lang 4.4 114.8 ×26.16 ×4.22 14% (1.2) 0% (0.0) 39% (3.1) 47% (3.8) 0% (0.0) match
cmn_Hani lang 5.2 134.0 ×25.92 ×9.51 19% (1.2) 0% (0.0) 38% (2.4) 41% (2.6) 1% (0.1) match
ell_Grek lang 5.3 133.8 ×25.28 ×6.85 18% (1.2) 0% (0.0) 35% (2.2) 47% (3.0) 0% (0.0) match
eng_Latn lang 4.0 95.6 ×23.89 ×2.21 27% (2.5) 0% (0.0) 32% (3.0) 40% (3.7) 0% (0.0) match
heb_Hebr lang 4.4 109.9 ×24.72 ×4.45 15% (1.2) 0% (0.0) 29% (2.3) 56% (4.4) 0% (0.0) match
hin_Deva lang 4.0 105.5 ×26.45 ×3.46 13% (1.2) 0% (0.0) 37% (3.2) 50% (4.4) 1% (0.1) match
jpn_Jpan lang 5.9 153.8 ×25.95 ×10.21 22% (1.2) 0% (0.0) 41% (2.2) 36% (1.9) 0% (0.0) match
kat_Geor lang 6.7 153.4 ×22.93 ×6.90 21% (1.2) 0% (0.0) 38% (2.1) 42% (2.3) 0% (0.0) match
kor_Hang lang 4.1 92.9 ×22.47 ×5.18 13% (1.2) 0% (0.0) 28% (2.5) 59% (5.2) 0% (0.0) match
rus_Cyrl lang 5.1 135.9 ×26.58 ×7.34 19% (1.2) 0% (0.0) 35% (2.2) 45% (2.8) 0% (0.0) match
tam_Taml lang 3.9 111.8 ×29.03 ×3.17 14% (1.2) 0% (0.0) 33% (2.7) 53% (4.5) 0% (0.0) match
tha_Thai lang 5.0 120.1 ×23.90 ×5.64 17% (1.2) 0% (0.0) 37% (2.6) 46% (3.2) 0% (0.0) match
added_normalized_dense modalities 6.1 183.4 ×30.13 ×7.12 28% (1.3) 0% (0.0) 23% (1.1) 52% (2.5) 0% (0.0) match
added_normalized_sparse modalities 5.5 144.1 ×26.39 ×3.54 29% (1.9) 0% (0.0) 31% (2.0) 43% (2.8) 0% (0.0) match
added_special_dense modalities 4.2 47.9 ×11.50 ×1.05 62% (12.6) 0% (0.1) 25% (5.1) 12% (2.5) 0% (0.0) match
added_special_sparse modalities 4.4 63.5 ×14.51 ×1.13 46% (6.9) 0% (0.0) 33% (4.8) 20% (3.0) 1% (0.1) match
agentic-traces modalities 3.6 87.3 ×24.53 ×2.49 23% (2.4) 0% (0.0) 36% (3.7) 41% (4.2) 0% (0.0) match
agentic_swe modalities 3.9 103.5 ×26.64 ×3.83 22% (1.9) 0% (0.0) 33% (2.9) 45% (4.0) 0% (0.0) match
code_mixed modalities 4.0 98.7 ×24.42 ×2.22 24% (2.2) 0% (0.0) 36% (3.3) 41% (3.8) 0% (0.0) match
math_latex modalities 3.8 89.0 ×23.27 ×2.32 24% (2.5) 0% (0.0) 34% (3.5) 41% (4.2) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.62 3.49 3.69 4.56 28.6 17.2 5.9 4.8 7.7× / 6.3× 4.6× / 3.8× 1.6× / 1.3× 1.3× / 1.0×
arb_Arab 1.00 3.04 2.33 4.37 32.7 19.5 6.7 5.2 14.1× / 7.5× 8.4× / 4.5× 2.9× / 1.5× 2.2× / 1.2×
ben_Beng 1.46 2.94 3.14 4.62 47.4 28.2 10.3 3.8 15.1× / 10.3× 9.0× / 6.1× 3.3× / 2.2× 1.2× / 0.8×
cmn_Hani 1.13 2.40 2.39 3.67 20.8 11.9 4.7 2.5 8.7× / 5.7× 5.0× / 3.3× 2.0× / 1.3× 1.0× / 0.7×
ell_Grek 0.58 3.02 2.22 4.66 29.5 17.2 6.1 4.8 13.3× / 6.3× 7.7× / 3.7× 2.8× / 1.3× 2.2× / 1.0×
eng_Latn 0.13 1.74 3.00 4.62 46.6 32.7 12.2 3.9 15.5× / 10.1× 10.9× / 7.1× 4.1× / 2.6× 1.3× / 0.8×
heb_Hebr 0.99 3.12 2.30 4.43 32.1 19.8 6.8 3.0 13.9× / 7.2× 8.6× / 4.5× 3.0× / 1.5× 1.3× / 0.7×
hin_Deva 1.36 3.11 3.24 4.99 50.6 30.7 11.1 4.1 15.6× / 10.2× 9.5× / 6.2× 3.4× / 2.2× 1.3× / 0.8×
jpn_Jpan 1.56 3.53 2.20 4.17 19.2 9.8 4.1 3.7 8.7× / 4.6× 4.4× / 2.3× 1.8× / 1.0× 1.7× / 0.9×
kat_Geor 1.38 2.55 2.10 3.27 17.8 11.2 4.1 2.1 8.5× / 5.4× 5.3× / 3.4× 2.0× / 1.3× 1.0× / 0.6×
kor_Hang 1.09 2.84 2.53 4.28 32.9 21.2 7.5 3.7 13.0× / 7.7× 8.4× / 5.0× 3.0× / 1.7× 1.5× / 0.9×
rus_Cyrl 1.03 2.94 2.17 4.08 28.1 17.0 5.8 2.5 12.9× / 6.9× 7.8× / 4.2× 2.7× / 1.4× 1.2× / 0.6×
tam_Taml 0.92 2.95 2.73 4.75 46.6 27.5 9.7 3.4 17.1× / 9.8× 10.1× / 5.8× 3.6× / 2.0× 1.3× / 0.7×
tha_Thai 1.37 2.59 2.61 3.83 29.5 16.0 6.7 3.0 11.3× / 7.7× 6.1× / 4.2× 2.6× / 1.7× 1.1× / 0.8×
added_normalized_dense 0.06 1.77 1.09 2.80 24.6 16.4 6.6 2.0 22.6× / 8.8× 15.0× / 5.8× 6.1× / 2.4× 1.8× / 0.7×
added_normalized_sparse 0.06 1.77 1.99 3.70 33.2 22.4 8.7 2.7 16.7× / 9.0× 11.3× / 6.1× 4.4× / 2.4× 1.4× / 0.7×
added_special_dense 0.06 1.77 5.12 6.83 100.4 73.0 21.0 3.5 19.6× / 14.7× 14.3× / 10.7× 4.1× / 3.1× 0.7× / 0.5×
added_special_sparse 0.06 1.77 4.84 6.55 64.3 45.6 15.0 3.6 13.3× / 9.8× 9.4× / 7.0× 3.1× / 2.3× 0.7× / 0.5×
agentic-traces 0.57 1.77 3.72 4.92 55.7 42.9 14.7 4.7 14.9× / 11.3× 11.5× / 8.7× 3.9× / 3.0× 1.3× / 1.0×
agentic_swe 0.52 1.74 2.90 4.12 57.4 51.1 15.3 3.5 19.8× / 13.9× 17.6× / 12.4× 5.3× / 3.7× 1.2× / 0.8×
code_mixed 0.10 1.72 3.29 4.91 55.4 49.7 15.0 4.1 16.8× / 11.3× 15.1× / 10.1× 4.6× / 3.0× 1.2× / 0.8×
math_latex 0.57 1.78 3.47 4.68 53.6 38.5 13.9 4.3 15.5× / 11.5× 11.1× / 8.2× 4.0× / 3.0× 1.2× / 0.9×
llama-2 — model-bounded BPE, no pre-tokenizer · ×4.21 vs v0.23.1 · ×1.15 vs base · decode pending llama-2 speedup llama-2 stage decomposition llama-2 thread scaling llama-2 decode speedup llama-2 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 19+0 (peak 23) · Pipeline 23+0 (peak 23)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 4.8 43.3 ×9.10 ×1.06 0% (0.0) 12% (2.8) 0% (0.0) 88% (19.8) 0% (0.0) match
arb_Arab lang 9.9 49.9 ×5.05 ×1.00 0% (0.0) 17% (3.2) 0% (0.0) 84% (16.3) 0% (0.0) match
ben_Beng lang 11.0 82.8 ×7.55 ×1.02 0% (0.0) 18% (2.2) 0% (0.0) 81% (9.6) 0% (0.0) match
cmn_Hani lang 9.6 67.2 ×7.02 ×1.09 0% (0.1) 3% (0.5) 0% (0.0) 97% (13.8) 0% (0.0) match
ell_Grek lang 9.8 57.2 ×5.82 ×1.00 0% (0.0) 19% (3.1) 0% (0.0) 82% (13.8) 0% (0.0) match
eng_Latn lang 4.1 6.5 ×1.58 ×1.05 0% (0.1) 5% (6.9) 0% (0.0) 96% (142.5) 0% (0.0) match
heb_Hebr lang 9.7 60.7 ×6.24 ×0.99 0% (0.0) 20% (3.3) 0% (0.0) 80% (12.9) 0% (0.0) match
hin_Deva lang 11.7 78.9 ×6.75 ×1.00 0% (0.0) 24% (2.9) 0% (0.0) 76% (9.3) 0% (0.0) match
jpn_Jpan lang 13.6 88.7 ×6.53 ×1.11 0% (0.1) 3% (0.4) 0% (0.0) 96% (10.5) 0% (0.0) match
kat_Geor lang 14.1 92.9 ×6.59 ×1.07 0% (0.0) 19% (1.9) 0% (0.0) 81% (8.4) 0% (0.0) match
kor_Hang lang 7.2 51.7 ×7.17 ×1.00 0% (0.1) 17% (3.3) 0% (0.0) 82% (15.3) 0% (0.0) match
rus_Cyrl lang 8.1 16.5 ×2.03 ×1.03 0% (0.0) 5% (2.8) 0% (0.0) 95% (57.7) 0% (0.1) match
tam_Taml lang 12.6 90.3 ×7.15 ×1.06 0% (0.0) 16% (1.8) 0% (0.0) 84% (9.0) 0% (0.0) match
tha_Thai lang 16.0 90.1 ×5.61 ×1.09 0% (0.0) 9% (1.0) 0% (0.0) 91% (9.9) 0% (0.0) match
added_normalized_dense modalities 5.4 9.0 ×1.65 ×1.03 0% (0.0) 3% (3.8) 0% (0.0) 97% (110.8) 0% (0.0) match
added_normalized_sparse modalities 4.7 7.7 ×1.63 ×1.05 0% (0.0) 5% (6.0) 0% (0.1) 95% (121.8) 0% (0.0) match
added_special_dense modalities 4.1 40.3 ×9.84 ×1.95 21% (5.1) 64% (15.7) 4% (1.0) 10% (2.6) 1% (0.2) match
added_special_sparse modalities 5.5 49.3 ×9.05 ×4.79 11% (2.1) 78% (14.4) 2% (0.3) 9% (1.7) 1% (0.1) match
agentic-traces modalities 4.4 7.4 ×1.68 ×1.06 0% (0.1) 5% (6.2) 0% (0.0) 95% (128.2) 0% (0.1) match
agentic_swe modalities 3.7 7.1 ×1.91 ×1.02 0% (0.0) 7% (9.8) 0% (0.0) 93% (127.9) 0% (0.0) match
code_mixed modalities 4.0 7.1 ×1.80 ×1.03 0% (0.0) 6% (8.0) 0% (0.0) 94% (129.9) 0% (0.0) match
math_latex modalities 4.3 7.0 ×1.64 ×1.05 0% (0.1) 5% (6.4) 0% (0.0) 95% (135.4) 0% (0.0) match
llama-3 — cl100k-regex byte-level BPE (llama-3), single regex · ×25.81 vs v0.23.1 · ×3.85 vs base · decode pending llama-3 speedup llama-3 stage decomposition llama-3 thread scaling llama-3 decode speedup llama-3 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 73+0 (peak 95) · Pipeline 92+0 (peak 94)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 4.4 105.4 ×24.15 ×2.20 8% (0.7) 0% (0.0) 47% (3.7) 46% (3.6) 0% (0.0) match
arb_Arab lang 4.9 136.8 ×28.06 ×7.68 10% (0.6) 0% (0.0) 36% (2.3) 54% (3.4) 1% (0.1) match
ben_Beng lang 4.1 115.4 ×27.97 ×3.71 7% (0.6) 0% (0.0) 39% (3.1) 53% (4.3) 0% (0.0) match
cmn_Hani lang 5.3 138.3 ×26.23 ×8.38 11% (0.6) 0% (0.0) 43% (2.4) 48% (2.7) 0% (0.0) match
ell_Grek lang 5.4 143.0 ×26.58 ×7.44 10% (0.6) 0% (0.0) 38% (2.2) 51% (3.0) 0% (0.0) match
eng_Latn lang 4.3 101.1 ×23.31 ×2.22 23% (2.0) 0% (0.0) 34% (3.0) 43% (3.7) 0% (0.0) match
heb_Hebr lang 4.4 117.3 ×26.48 ×4.68 8% (0.6) 0% (0.0) 32% (2.3) 60% (4.3) 0% (0.0) match
hin_Deva lang 4.5 133.6 ×29.44 ×1.75 9% (0.6) 0% (0.0) 47% (3.2) 44% (3.0) 0% (0.0) match
jpn_Jpan lang 6.0 166.8 ×27.82 ×10.56 13% (0.6) 0% (0.0) 46% (2.2) 41% (1.9) 0% (0.0) match
kat_Geor lang 5.8 157.6 ×27.07 ×4.13 12% (0.6) 0% (0.0) 41% (2.1) 47% (2.4) 0% (0.0) match
kor_Hang lang 4.2 101.9 ×24.28 ×5.49 8% (0.6) 0% (0.0) 31% (2.5) 61% (4.9) 0% (0.0) match
rus_Cyrl lang 5.2 146.6 ×28.00 ×8.87 11% (0.6) 0% (0.0) 38% (2.2) 51% (2.9) 0% (0.0) match
tam_Taml lang 4.0 118.3 ×29.50 ×3.49 8% (0.6) 0% (0.0) 35% (2.7) 57% (4.5) 0% (0.0) match
tha_Thai lang 5.4 141.0 ×25.89 ×7.07 10% (0.6) 0% (0.0) 43% (2.6) 46% (2.8) 1% (0.1) match
added_normalized_dense modalities 6.2 207.2 ×33.33 ×8.06 18% (0.8) 0% (0.0) 24% (1.0) 58% (2.4) 0% (0.0) match
added_normalized_sparse modalities 5.5 157.4 ×28.66 ×3.78 23% (1.3) 0% (0.0) 34% (2.0) 44% (2.6) 1% (0.1) match
added_special_dense modalities 4.3 76.7 ×17.88 ×1.07 40% (4.9) 0% (0.1) 39% (4.8) 21% (2.7) 0% (0.0) match
added_special_sparse modalities 4.5 83.8 ×18.66 ×1.18 30% (3.2) 0% (0.0) 43% (4.7) 28% (3.0) 0% (0.0) match
agentic-traces modalities 3.7 93.7 ×25.09 ×2.53 18% (1.8) 0% (0.0) 38% (3.7) 44% (4.2) 0% (0.0) match
agentic_swe modalities 4.3 111.6 ×26.18 ×3.96 16% (1.3) 0% (0.0) 35% (2.9) 49% (3.9) 0% (0.0) match
code_mixed modalities 4.4 106.1 ×24.24 ×2.28 18% (1.5) 0% (0.0) 38% (3.3) 44% (3.7) 0% (0.0) match
math_latex modalities 3.9 94.8 ×24.03 ×2.35 20% (1.9) 0% (0.0) 36% (3.4) 44% (4.1) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.63 3.47 3.67 4.50 26.1 15.7 6.0 4.8 7.1× / 5.8× 4.3× / 3.5× 1.6× / 1.3× 1.3× / 1.1×
arb_Arab 1.00 3.02 2.31 4.34 30.1 19.1 6.9 5.2 13.0× / 6.9× 8.2× / 4.4× 3.0× / 1.6× 2.2× / 1.2×
ben_Beng 1.46 2.94 3.14 4.62 43.0 26.9 10.3 3.7 13.7× / 9.3× 8.5× / 5.8× 3.3× / 2.2× 1.2× / 0.8×
cmn_Hani 1.13 2.33 2.37 3.57 19.3 11.6 4.7 2.4 8.2× / 5.4× 4.9× / 3.3× 2.0× / 1.3× 1.0× / 0.7×
ell_Grek 0.58 3.02 2.18 4.62 27.1 17.0 6.0 4.8 12.4× / 5.9× 7.8× / 3.7× 2.8× / 1.3× 2.2× / 1.0×
eng_Latn 0.09 1.74 2.96 4.61 41.6 32.4 12.3 3.9 14.1× / 9.0× 10.9× / 7.0× 4.2× / 2.7× 1.3× / 0.8×
heb_Hebr 0.99 3.11 2.31 4.43 29.4 19.7 6.9 3.0 12.7× / 6.6× 8.5× / 4.5× 3.0× / 1.6× 1.3× / 0.7×
hin_Deva 1.36 3.16 3.22 5.02 45.7 29.9 11.2 4.1 14.2× / 9.1× 9.3× / 6.0× 3.5× / 2.2× 1.3× / 0.8×
jpn_Jpan 1.56 3.53 2.17 4.15 17.9 9.6 4.1 3.7 8.2× / 4.3× 4.4× / 2.3× 1.9× / 1.0× 1.7× / 0.9×
kat_Geor 1.39 2.55 2.08 3.24 16.3 11.1 4.1 2.1 7.9× / 5.0× 5.4× / 3.4× 2.0× / 1.3× 1.0× / 0.6×
kor_Hang 1.08 2.84 2.52 4.28 29.7 21.2 7.4 3.7 11.8× / 6.9× 8.4× / 4.9× 2.9× / 1.7× 1.5× / 0.9×
rus_Cyrl 1.02 3.02 2.16 4.15 26.0 16.4 5.9 2.5 12.0× / 6.3× 7.6× / 4.0× 2.8× / 1.4× 1.2× / 0.6×
tam_Taml 0.92 2.96 2.74 4.77 42.3 26.6 10.2 3.4 15.4× / 8.9× 9.7× / 5.6× 3.7× / 2.1× 1.3× / 0.7×
tha_Thai 1.37 2.61 2.60 3.84 27.0 15.8 6.7 3.1 10.4× / 7.0× 6.1× / 4.1× 2.6× / 1.7× 1.2× / 0.8×
added_normalized_dense 0.09 1.77 1.02 2.69 22.1 16.4 6.5 1.9 21.7× / 8.2× 16.1× / 6.1× 6.4× / 2.4× 1.9× / 0.7×
added_normalized_sparse 0.10 1.77 1.99 3.66 29.5 22.6 8.7 2.7 14.8× / 8.1× 11.3× / 6.2× 4.4× / 2.4× 1.3× / 0.7×
added_special_dense 0.10 1.77 4.79 6.45 90.0 71.2 21.0 3.4 18.8× / 14.0× 14.9× / 11.0× 4.4× / 3.3× 0.7× / 0.5×
added_special_sparse 0.10 1.77 4.68 6.35 57.1 45.0 15.4 3.6 12.2× / 9.0× 9.6× / 7.1× 3.3× / 2.4× 0.8× / 0.6×
agentic-traces 0.57 1.75 3.67 4.86 50.1 42.9 15.0 4.7 13.6× / 10.3× 11.7× / 8.8× 4.1× / 3.1× 1.3× / 1.0×
agentic_swe 0.51 1.73 2.86 4.08 52.3 51.1 15.5 3.5 18.3× / 12.8× 17.9× / 12.5× 5.4× / 3.8× 1.2× / 0.8×
code_mixed 0.06 1.73 3.26 4.93 49.4 50.1 15.0 4.0 15.2× / 10.0× 15.3× / 10.2× 4.6× / 3.0× 1.2× / 0.8×
math_latex 0.56 1.76 3.39 4.60 47.6 38.1 13.9 4.3 14.0× / 10.4× 11.2× / 8.3× 4.1× / 3.0× 1.3× / 0.9×
mistral-small-4 — tekken byte-level BPE, 1k added specials (mistral-small-4) · ×7.94 vs v0.23.1 · ×1.55 vs base · decode pending mistral-small-4 speedup mistral-small-4 stage decomposition mistral-small-4 thread scaling mistral-small-4 decode speedup mistral-small-4 decode thread scaling

Memory (RSS MB, load+encode): v0.23.1 152+0 (peak 194) · Pipeline 109+0 (peak 194)

Fixture Group v0.23.1 MB/s Pipeline MB/s Speedup Δ base added-token normalize pre-tokenize model post Ids
amh_Ethi lang 3.9 46.7 ×12.05 ×1.12 6% (1.2) 0% (0.0) 75% (14.7) 19% (3.7) 0% (0.0) match
arb_Arab lang 4.8 45.0 ×9.45 ×2.14 6% (1.2) 0% (0.0) 80% (16.6) 15% (3.1) 0% (0.0) match
ben_Beng lang 7.0 64.4 ×9.24 ×3.40 8% (1.2) 0% (0.0) 76% (11.2) 16% (2.3) 0% (0.0) match
cmn_Hani lang 5.1 58.0 ×11.28 ×3.35 7% (1.2) 0% (0.0) 75% (11.9) 18% (2.8) 0% (0.0) match
ell_Grek lang 5.3 48.5 ×9.22 ×2.63 6% (1.2) 0% (0.0) 78% (15.7) 16% (3.2) 0% (0.0) match
eng_Latn lang 4.0 26.2 ×6.54 ×0.68 7% (2.5) 0% (0.0) 82% (30.8) 11% (4.1) 0% (0.0) match
heb_Hebr lang 4.7 43.1 ×9.10 ×2.54 5% (1.2) 0% (0.0) 78% (17.8) 17% (3.8) 0% (0.0) match
hin_Deva lang 6.9 57.0 ×8.23 ×2.25 7% (1.2) 0% (0.0) 79% (13.4) 14% (2.4) 0% (0.0) match
jpn_Jpan lang 5.8 70.4 ×12.12 ×4.41 9% (1.2) 0% (0.0) 75% (9.9) 15% (2.0) 0% (0.0) match
kat_Geor lang 6.9 68.3 ×9.96 ×4.60 8% (1.2) 0% (0.0) 75% (10.5) 17% (2.3) 0% (0.0) match
kor_Hang lang 4.3 37.3 ×8.67 ×1.96 5% (1.2) 0% (0.0) 76% (19.8) 19% (4.9) 0% (0.1) match
rus_Cyrl lang 5.2 48.9 ×9.45 ×2.95 6% (1.2) 0% (0.0) 79% (15.3) 16% (3.0) 0% (0.0) match
tam_Taml lang 7.2 77.6 ×10.71 ×5.16 9% (1.2) 0% (0.0) 74% (9.0) 17% (2.1) 0% (0.0) match
tha_Thai lang 8.3 111.9 ×13.47 ×7.63 14% (1.2) 0% (0.0) 72% (6.0) 13% (1.1) 0% (0.0) match
added_normalized_dense modalities 5.8 46.0 ×7.94 ×1.62 6% (1.3) 0% (0.0) 81% (17.7) 12% (2.7) 0% (0.1) match
added_normalized_sparse modalities 5.5 38.7 ×6.98 ×0.92 7% (1.9) 0% (0.0) 81% (21.2) 12% (3.2) 0% (0.0) match
added_special_dense modalities 4.4 16.8 ×3.84 ×0.24 9% (5.1) 0% (0.0) 86% (51.0) 6% (3.3) 0% (0.0) match
added_special_sparse modalities 4.7 23.2 ×4.92 ×0.36 8% (3.5) 0% (0.0) 83% (35.5) 9% (3.7) 0% (0.0) match
agentic-traces modalities 3.5 19.9 ×5.60 ×0.58 5% (2.3) 0% (0.0) 86% (43.9) 9% (4.8) 0% (0.0) match
agentic_swe modalities 3.6 16.8 ×4.72 ×0.68 3% (1.9) 0% (0.0) 89% (54.1) 8% (4.6) 0% (0.1) match
code_mixed modalities 3.8 18.3 ×4.82 ×0.43 4% (2.1) 0% (0.0) 88% (48.5) 8% (4.1) 0% (0.2) match
math_latex modalities 3.6 22.1 ×6.05 ×0.56 5% (2.4) 0% (0.0) 84% (37.9) 11% (4.8) 0% (0.0) match

Pre-tokenize: classify + fsm vs regex engines — ns/byte, lower better. The fsm is the scalar jump-table in both pipe columns; SIMD / scalar is the classify pass (regex pre-tokenizers have no SIMD fsm). ×vs = engine ÷ our pipeline (SIMD / scalar classify); onig & pcre2 (JIT) are C, fancy is pure-Rust fancy-regex, logos is a compile-time DFA lexer (approximate grammar; n/a for deepseek).

Fixture classify SIMD classify scalar pipe (SIMD cls + fsm) pipe (scalar cls + fsm) onig fancy pcre2 logos ×vs onig ×vs fancy ×vs pcre2 ×vs logos
amh_Ethi 2.63 3.47 14.69 15.53 28.4 14.2 6.6 1.9× / 1.8× 1.0× / 0.9× 0.5× / 0.4×
arb_Arab 1.00 3.01 16.65 18.66 32.6 16.3 7.3 2.0× / 1.7× 1.0× / 0.9× 0.4× / 0.4×
ben_Beng 1.46 2.96 11.22 12.72 22.9 11.0 5.2 2.0× / 1.8× 1.0× / 0.9× 0.5× / 0.4×
cmn_Hani 1.13 2.38 11.87 13.12 21.6 11.6 5.5 1.8× / 1.6× 1.0× / 0.9× 0.5× / 0.4×
ell_Grek 0.58 3.04 15.66 18.12 28.5 15.2 6.5 1.8× / 1.6× 1.0× / 0.8× 0.4× / 0.4×
eng_Latn 0.10 1.76 30.79 32.45 40.7 30.1 13.2 1.3× / 1.3× 1.0× / 0.9× 0.4× / 0.4×
heb_Hebr 0.99 3.08 17.79 19.87 31.9 17.1 7.7 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
hin_Deva 1.37 3.18 13.45 15.25 24.6 12.8 6.1 1.8× / 1.6× 1.0× / 0.8× 0.5× / 0.4×
jpn_Jpan 1.56 3.52 9.92 11.89 20.4 9.7 4.8 2.1× / 1.7× 1.0× / 0.8× 0.5× / 0.4×
kat_Geor 1.39 2.54 10.47 11.61 18.4 10.5 4.4 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
kor_Hang 1.08 2.77 19.85 21.53 32.2 19.2 8.7 1.6× / 1.5× 1.0× / 0.9× 0.4× / 0.4×
rus_Cyrl 1.02 2.99 15.34 17.31 27.8 15.1 6.3 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
tam_Taml 0.93 2.95 9.04 11.06 18.6 8.8 4.1 2.1× / 1.7× 1.0× / 0.8× 0.5× / 0.4×
tha_Thai 1.37 2.58 5.99 7.20 13.2 5.9 2.8 2.2× / 1.8× 1.0× / 0.8× 0.5× / 0.4×
added_normalized_dense 0.24 1.77 17.68 19.20 30.0 17.3 11.3 1.7× / 1.6× 1.0× / 0.9× 0.6× / 0.6×
added_normalized_sparse 0.25 1.77 21.18 22.70 32.2 20.3 11.1 1.5× / 1.4× 1.0× / 0.9× 0.5× / 0.5×
added_special_dense 0.24 1.77 51.04 52.56 81.4 66.2 23.1 1.6× / 1.5× 1.3× / 1.3× 0.5× / 0.4×
added_special_sparse 0.24 1.77 35.54 37.06 52.8 40.9 15.9 1.5× / 1.4× 1.2× / 1.1× 0.4× / 0.4×
agentic-traces 0.69 1.77 43.90 44.98 51.5 42.7 16.9 1.2× / 1.1× 1.0× / 0.9× 0.4× / 0.4×
agentic_swe 0.51 1.75 54.12 55.37 55.7 53.5 17.9 1.0× / 1.0× 1.0× / 1.0× 0.3× / 0.3×
code_mixed 0.07 1.73 48.52 50.17 50.9 47.9 17.0 1.0× / 1.0× 1.0× / 1.0× 0.4× / 0.3×
math_latex 0.56 1.77 37.89 39.11 48.3 37.4 15.5 1.3× / 1.2× 1.0× / 1.0× 0.4× / 0.4×
Not yet supported: t5-base
t5-base not supported

pack_word copied `len` bytes at a time, which is a call into memcpy and a
branch that mispredicts on every short word. Read the 16 bytes at once and
mask the surplus, declining the wide load when it would cross a page.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

let mut lanes = [0u8; 16];
lanes[..len].copy_from_slice(word);
Some(u128::from_le_bytes(lanes) | ((len as u128) << 120))
let ptr = word.as_ptr();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are masking raw even in the else branch which is probably not optimal 👀
ff to push to fix if this has an impact!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants