Skip to content

WordCache: FlatCache tricks - #2247

Merged
SBrandeis merged 8 commits into
feat/bpe-cachefrom
feat/flat-inplace-cache
Jul 29, 2026
Merged

WordCache: FlatCache tricks#2247
SBrandeis merged 8 commits into
feat/bpe-cachefrom
feat/flat-inplace-cache

Conversation

@SBrandeis

@SBrandeis SBrandeis commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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

2f16acfce · 2026-07-28 22:06 UTC · Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz · 8 cores

Per-model encode throughput vs latest release

vs base branch (709ef7af5) — 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 · ×4.89 vs v0.23.1 · ×0.99 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+0 (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.8 27.8 ×3.57 ×1.01 3% (1.2) 76% (27.4) 13% (4.9) 7% (2.6) 0% (0.1) match
arb_Arab lang 4.2 24.4 ×5.82 ×0.98 3% (1.2) 68% (27.5) 8% (3.3) 21% (8.6) 0% (0.0) match
ben_Beng lang 6.0 33.9 ×5.63 ×0.97 4% (1.2) 65% (19.1) 10% (2.9) 21% (6.0) 0% (0.0) match
cmn_Hani lang 3.9 18.9 ×4.88 ×1.00 2% (1.2) 71% (37.7) 11% (5.7) 16% (8.4) 0% (0.0) match
ell_Grek lang 3.8 23.3 ×6.17 ×0.98 3% (1.2) 67% (28.7) 8% (3.4) 22% (9.4) 0% (0.0) match
eng_Latn lang 4.4 18.4 ×4.15 ×1.00 5% (2.5) 71% (38.5) 8% (4.4) 16% (8.7) 0% (0.0) match
heb_Hebr lang 4.2 19.7 ×4.68 ×0.99 2% (1.2) 74% (37.4) 7% (3.8) 17% (8.4) 0% (0.0) match
hin_Deva lang 6.5 27.2 ×4.19 ×0.99 3% (1.2) 73% (27.0) 9% (3.2) 15% (5.4) 0% (0.0) match
jpn_Jpan lang 4.3 26.9 ×6.29 ×0.98 3% (1.2) 63% (23.3) 13% (4.6) 21% (7.9) 0% (0.0) match
kat_Geor lang 6.1 27.8 ×4.51 ×0.99 3% (1.2) 71% (26.5) 9% (3.3) 13% (4.9) 5% (1.7) match
kor_Hang lang 2.4 17.1 ×7.03 ×0.96 2% (1.2) 60% (35.2) 13% (7.3) 25% (14.8) 0% (0.1) match
rus_Cyrl lang 3.7 23.3 ×6.38 ×0.98 3% (1.2) 64% (27.4) 7% (3.2) 25% (10.8) 0% (0.0) match
tam_Taml lang 7.0 37.8 ×5.38 ×0.99 4% (1.2) 71% (18.6) 10% (2.6) 15% (3.9) 0% (0.0) match
tha_Thai lang 8.3 33.2 ×3.99 ×1.02 4% (1.2) 83% (25.0) 8% (2.4) 5% (1.5) 0% (0.0) match
added_normalized_dense modalities 6.8 19.6 ×2.88 ×0.99 3% (1.3) 81% (40.6) 14% (7.0) 2% (1.1) 0% (0.0) match
added_normalized_sparse modalities 5.3 18.3 ×3.45 ×0.99 3% (1.9) 75% (40.0) 13% (6.9) 9% (4.9) 0% (0.0) match
added_special_dense modalities 5.3 38.4 ×7.19 ×0.99 21% (5.1) 36% (9.1) 36% (9.1) 7% (1.7) 0% (0.1) match
added_special_sparse modalities 4.0 21.2 ×5.29 ×0.99 8% (3.6) 60% (27.9) 19% (8.9) 13% (5.9) 0% (0.0) match
agentic-traces modalities 3.8 18.2 ×4.75 ×1.00 4% (2.3) 70% (38.4) 9% (4.9) 17% (9.1) 0% (0.0) match
agentic_swe modalities 4.1 19.5 ×4.76 ×1.00 4% (1.9) 76% (38.5) 7% (3.6) 14% (7.1) 0% (0.0) match
code_mixed modalities 3.9 19.0 ×4.83 ×1.00 4% (2.1) 73% (38.4) 8% (4.3) 14% (7.6) 0% (0.2) match
math_latex modalities 4.0 18.2 ×4.56 ×1.00 5% (2.5) 71% (38.5) 9% (4.9) 16% (8.9) 0% (0.0) match
deepseek-v4 — deepseek 3-regex split-heavy byte-level BPE · ×25.36 vs v0.23.1 · ×6.00 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 68) · 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 91.8 ×21.18 ×2.68 7% (0.7) 0% (0.0) 51% (4.7) 43% (4.0) 0% (0.0) match
arb_Arab lang 4.1 111.7 ×27.28 ×6.72 8% (0.6) 0% (0.0) 45% (3.4) 48% (3.6) 0% (0.0) match
ben_Beng lang 6.2 139.4 ×22.49 ×7.82 9% (0.6) 0% (0.0) 51% (3.2) 41% (2.6) 0% (0.0) match
cmn_Hani lang 3.6 111.3 ×31.06 ×6.73 11% (0.8) 0% (0.0) 45% (3.2) 45% (3.2) 0% (0.0) match
ell_Grek lang 4.6 117.1 ×25.66 ×6.55 8% (0.6) 0% (0.0) 47% (3.4) 45% (3.3) 0% (0.0) match
eng_Latn lang 3.1 81.8 ×26.72 ×6.29 18% (2.0) 0% (0.0) 46% (5.1) 36% (3.9) 1% (0.1) match
heb_Hebr lang 3.8 106.1 ×27.60 ×8.18 7% (0.6) 0% (0.0) 43% (3.5) 51% (4.2) 0% (0.0) match
hin_Deva lang 5.9 129.5 ×22.04 ×6.08 9% (0.6) 0% (0.0) 51% (3.4) 42% (2.8) 0% (0.0) match
jpn_Jpan lang 4.1 131.5 ×31.86 ×7.32 10% (0.7) 0% (0.0) 47% (3.0) 40% (2.5) 2% (0.1) match
kat_Geor lang 5.8 140.3 ×24.01 ×8.07 10% (0.6) 0% (0.0) 50% (2.9) 41% (2.4) 0% (0.0) match
kor_Hang lang 3.4 88.1 ×26.25 ×4.46 6% (0.6) 0% (0.0) 38% (3.7) 56% (5.4) 0% (0.0) match
rus_Cyrl lang 4.1 120.1 ×29.09 ×8.48 9% (0.6) 0% (0.0) 47% (3.3) 45% (3.1) 0% (0.0) match
tam_Taml lang 5.9 150.9 ×25.54 ×8.64 11% (0.6) 0% (0.0) 50% (2.7) 39% (2.1) 0% (0.0) match
tha_Thai lang 6.7 206.9 ×30.74 ×14.45 15% (0.6) 0% (0.0) 55% (2.2) 31% (1.2) 0% (0.0) match
added_normalized_dense modalities 6.1 154.4 ×25.18 ×6.58 12% (0.7) 0% (0.0) 46% (2.8) 42% (2.5) 0% (0.0) match
added_normalized_sparse modalities 5.5 119.9 ×21.89 ×6.12 16% (1.2) 0% (0.0) 49% (3.7) 37% (2.9) 0% (0.0) match
added_special_dense modalities 3.7 58.5 ×15.80 ×1.56 39% (6.4) 4% (0.6) 36% (5.9) 22% (3.6) 0% (0.0) match
added_special_sparse modalities 3.9 65.3 ×16.55 ×3.14 27% (3.9) 0% (0.0) 46% (6.6) 26% (3.8) 1% (0.1) match
agentic-traces modalities 2.8 78.5 ×28.22 ×5.50 15% (1.8) 0% (0.0) 46% (5.4) 41% (4.9) 0% (0.0) match
agentic_swe modalities 3.0 99.4 ×33.35 ×6.67 14% (1.3) 0% (0.0) 42% (3.8) 44% (4.0) 0% (0.0) match
code_mixed modalities 3.5 91.3 ×25.97 ×5.87 15% (1.6) 0% (0.0) 45% (4.6) 40% (4.1) 0% (0.0) match
math_latex modalities 2.8 80.0 ×28.59 ×5.71 16% (1.9) 0% (0.0) 46% (5.3) 39% (4.5) 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.85 3.42 4.75 5.31 42.5 20.8 9.2 9.0× / 8.0× 4.4× / 3.9× 1.9× / 1.7×
arb_Arab 1.15 2.94 3.38 5.18 49.6 23.4 10.2 14.6× / 9.6× 6.9× / 4.5× 3.0× / 2.0×
ben_Beng 1.61 2.94 3.16 4.49 36.4 16.5 7.5 11.5× / 8.1× 5.2× / 3.7× 2.4× / 1.7×
cmn_Hani 1.13 2.22 3.19 4.28 61.3 34.3 14.3 19.2× / 14.3× 10.8× / 8.0× 4.5× / 3.3×
ell_Grek 0.58 2.93 3.44 5.78 47.7 21.5 9.7 13.9× / 8.3× 6.2× / 3.7× 2.8× / 1.7×
eng_Latn 0.09 1.53 5.10 6.53 66.0 40.7 16.2 13.0× / 10.1× 8.0× / 6.2× 3.2× / 2.5×
heb_Hebr 1.15 3.00 3.53 5.38 51.5 24.8 10.8 14.6× / 9.6× 7.0× / 4.6× 3.1× / 2.0×
hin_Deva 1.52 3.06 3.43 4.97 38.4 19.3 8.5 11.2× / 7.7× 5.6× / 3.9× 2.5× / 1.7×
jpn_Jpan 1.70 3.37 3.00 4.67 53.8 27.4 11.8 17.9× / 11.5× 9.1× / 5.9× 3.9× / 2.5×
kat_Geor 1.55 2.58 2.94 3.97 32.5 15.3 7.2 11.1× / 8.2× 5.2× / 3.9× 2.4× / 1.8×
kor_Hang 1.22 2.73 3.68 5.18 50.8 27.9 11.9 13.8× / 9.8× 7.6× / 5.4× 3.2× / 2.3×
rus_Cyrl 1.16 2.92 3.25 5.01 47.9 21.6 9.5 14.7× / 9.6× 6.6× / 4.3× 2.9× / 1.9×
tam_Taml 0.93 2.96 2.71 4.74 32.2 13.7 6.5 11.9× / 6.8× 5.0× / 2.9× 2.4× / 1.4×
tha_Thai 1.52 2.57 2.16 3.21 26.7 10.1 5.2 12.4× / 8.3× 4.7× / 3.2× 2.4× / 1.6×
added_normalized_dense 0.06 1.48 2.77 4.19 42.0 20.5 9.0 15.2× / 10.0× 7.4× / 4.9× 3.3× / 2.2×
added_normalized_sparse 0.06 1.47 3.75 5.16 49.2 26.5 11.3 13.1× / 9.5× 7.1× / 5.1× 3.0× / 2.2×
added_special_dense 0.06 1.47 5.86 7.28 175.5 99.2 38.1 29.9× / 24.1× 16.9× / 13.6× 6.5× / 5.2×
added_special_sparse 0.06 1.47 6.58 7.99 103.6 58.5 23.6 15.7× / 13.0× 8.9× / 7.3× 3.6× / 3.0×
agentic-traces 0.74 1.49 5.37 6.12 81.1 54.7 20.2 15.1× / 13.3× 10.2× / 8.9× 3.8× / 3.3×
agentic_swe 0.65 1.49 3.83 4.67 96.7 66.9 23.8 25.2× / 20.7× 17.5× / 14.3× 6.2× / 5.1×
code_mixed 0.09 1.47 4.60 5.98 74.5 55.1 18.7 16.2× / 12.4× 12.0× / 9.2× 4.1× / 3.1×
math_latex 0.73 1.52 5.29 6.08 79.4 49.3 19.5 15.0× / 13.1× 9.3× / 8.1× 3.7× / 3.2×
gemma-4 — byte-fallback BPE, Metaspace-style split (gemma-4) · ×2.09 vs v0.23.1 · ×1.09 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.4 27.3 ×2.64 ×0.99 2% (0.7) 6% (2.1) 0% (0.0) 92% (31.9) 0% (0.0) match
arb_Arab lang 7.0 12.5 ×1.78 ×0.94 1% (0.6) 3% (2.5) 0% (0.0) 95% (71.6) 1% (0.6) match
ben_Beng lang 9.7 18.3 ×1.88 ×0.98 1% (0.6) 3% (1.7) 0% (0.0) 96% (50.6) 0% (0.1) match
cmn_Hani lang 11.7 33.6 ×2.88 ×1.00 2% (0.6) 1% (0.3) 0% (0.0) 98% (26.6) 0% (0.0) match
ell_Grek lang 7.5 14.8 ×1.96 ×0.99 1% (0.6) 4% (2.5) 0% (0.0) 95% (62.9) 0% (0.0) match
eng_Latn lang 3.7 5.4 ×1.45 ×0.99 1% (2.0) 3% (4.8) 0% (0.0) 97% (176.4) 0% (0.0) match
heb_Hebr lang 7.8 16.6 ×2.13 ×0.99 1% (0.6) 4% (2.6) 0% (0.0) 95% (55.5) 0% (0.0) match
hin_Deva lang 9.3 18.1 ×1.93 ×1.01 1% (0.6) 4% (2.3) 0% (0.0) 95% (50.9) 0% (0.0) match
jpn_Jpan lang 12.5 29.1 ×2.33 ×1.00 2% (0.6) 1% (0.2) 0% (0.0) 98% (31.7) 0% (0.0) match
kat_Geor lang 11.8 24.7 ×2.09 ×1.01 2% (0.6) 4% (1.4) 0% (0.0) 95% (37.3) 0% (0.0) match
kor_Hang lang 9.3 25.7 ×2.75 ×1.02 2% (0.6) 7% (2.6) 0% (0.0) 91% (33.7) 0% (0.1) match
rus_Cyrl lang 7.0 10.8 ×1.53 ×0.97 1% (0.6) 2% (2.3) 0% (0.0) 96% (88.0) 1% (0.5) match
tam_Taml lang 10.9 19.7 ×1.81 ×1.01 1% (0.6) 3% (1.3) 0% (0.0) 95% (47.4) 1% (0.4) match
tha_Thai lang 12.8 23.9 ×1.87 ×1.00 2% (0.6) 2% (0.7) 0% (0.0) 97% (38.8) 0% (0.0) match
added_normalized_dense modalities 5.1 7.2 ×1.42 ×0.97 1% (0.7) 2% (2.9) 0% (0.1) 96% (130.1) 2% (2.2) match
added_normalized_sparse modalities 4.6 6.4 ×1.39 ×0.97 1% (1.3) 3% (4.4) 0% (0.0) 97% (145.8) 0% (0.0) match
added_special_dense modalities 4.7 33.8 ×7.20 ×1.67 35% (9.6) 29% (8.2) 28% (7.8) 8% (2.3) 0% (0.0) match
added_special_sparse modalities 7.0 44.8 ×6.39 ×4.58 26% (5.2) 41% (8.4) 25% (5.0) 7% (1.4) 1% (0.2) match
agentic-traces modalities 4.2 6.3 ×1.51 ×0.98 1% (1.8) 3% (4.4) 0% (0.0) 96% (151.2) 1% (0.8) match
agentic_swe modalities 3.9 6.8 ×1.73 ×0.99 1% (1.3) 5% (7.3) 0% (0.0) 94% (137.6) 0% (0.0) match
code_mixed modalities 4.0 6.4 ×1.58 ×0.98 1% (1.6) 4% (6.0) 0% (0.0) 96% (147.5) 0% (0.0) match
math_latex modalities 4.0 5.9 ×1.46 ×0.98 1% (1.9) 3% (4.5) 0% (0.0) 96% (163.0) 0% (0.5) match
gpt2 — gpt2 ByteLevel regex · ×30.08 vs v0.23.1 · ×3.66 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.6 90.9 ×25.41 ×1.87 8% (0.7) 0% (0.0) 45% (3.7) 48% (3.9) 0% (0.0) match
arb_Arab lang 3.4 107.5 ×31.50 ×4.19 8% (0.6) 0% (0.0) 31% (2.3) 62% (4.5) 0% (0.0) match
ben_Beng lang 2.7 90.7 ×33.83 ×2.05 6% (0.6) 0% (0.0) 31% (3.0) 64% (6.3) 0% (0.0) match
cmn_Hani lang 3.5 113.0 ×31.87 ×3.92 9% (0.6) 0% (0.0) 36% (2.3) 56% (3.6) 0% (0.0) match
ell_Grek lang 4.0 120.5 ×29.89 ×4.25 9% (0.6) 0% (0.0) 32% (2.2) 61% (4.1) 0% (0.0) match
eng_Latn lang 3.3 98.5 ×30.12 ×7.01 22% (2.0) 0% (0.0) 34% (2.9) 46% (4.0) 0% (0.0) match
heb_Hebr lang 3.7 112.3 ×29.99 ×3.90 8% (0.6) 0% (0.0) 30% (2.3) 63% (4.8) 0% (0.0) match
hin_Deva lang 3.0 105.8 ×35.65 ×2.61 7% (0.6) 0% (0.0) 35% (3.1) 60% (5.3) 0% (0.0) match
jpn_Jpan lang 4.3 143.5 ×33.02 ×6.52 11% (0.6) 0% (0.0) 39% (2.1) 50% (2.7) 0% (0.0) match
kat_Geor lang 4.6 149.7 ×32.79 ×2.30 11% (0.6) 0% (0.0) 39% (2.1) 51% (2.7) 0% (0.0) match
kor_Hang lang 3.2 95.1 ×29.53 ×2.18 7% (0.6) 0% (0.0) 27% (2.4) 66% (5.9) 0% (0.0) match
rus_Cyrl lang 4.0 122.3 ×30.85 ×4.42 9% (0.6) 0% (0.0) 31% (2.1) 61% (4.1) 0% (0.0) match
tam_Taml lang 2.6 105.6 ×40.08 ×1.46 7% (0.6) 0% (0.0) 30% (2.6) 63% (5.7) 0% (0.0) match
tha_Thai lang 3.4 110.1 ×32.68 ×3.10 8% (0.6) 0% (0.0) 33% (2.5) 61% (4.6) 0% (0.0) match
added_normalized_dense modalities 5.9 187.2 ×31.82 ×7.36 16% (0.7) 0% (0.0) 23% (1.1) 64% (2.9) 0% (0.0) match
added_normalized_sparse modalities 5.0 145.7 ×28.97 ×6.76 21% (1.3) 0% (0.0) 31% (2.0) 51% (3.2) 0% (0.0) match
added_special_dense modalities 4.0 78.8 ×19.47 ×1.65 44% (5.2) 0% (0.0) 34% (4.0) 23% (2.7) 0% (0.0) match
added_special_sparse modalities 4.2 79.8 ×19.18 ×3.34 30% (3.2) 0% (0.0) 38% (4.2) 35% (3.9) 0% (0.0) match
agentic-traces modalities 3.0 89.2 ×29.91 ×5.52 17% (1.8) 0% (0.0) 34% (3.5) 49% (5.0) 0% (0.0) match
agentic_swe modalities 3.2 106.8 ×33.06 ×4.45 15% (1.3) 0% (0.0) 27% (2.4) 57% (4.9) 1% (0.1) match
code_mixed modalities 3.4 100.1 ×29.41 ×4.88 17% (1.5) 0% (0.0) 31% (2.9) 53% (4.9) 0% (0.0) match
math_latex modalities 3.0 94.1 ×30.91 ×6.18 20% (1.9) 0% (0.0) 34% (3.2) 47% (4.5) 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.78 3.44 3.66 4.31 28.2 21.8 5.8 4.8 7.7× / 6.5× 6.0× / 5.0× 1.6× / 1.3× 1.3× / 1.1×
arb_Arab 1.15 2.95 2.26 4.06 33.0 27.2 6.8 5.1 14.6× / 8.1× 12.0× / 6.7× 3.0× / 1.7× 2.3× / 1.3×
ben_Beng 1.62 2.91 2.99 4.28 68.4 59.5 13.9 4.0 22.9× / 16.0× 19.9× / 13.9× 4.7× / 3.3× 1.3× / 0.9×
cmn_Hani 1.12 2.25 2.31 3.45 27.0 22.1 6.0 2.4 11.7× / 7.8× 9.6× / 6.4× 2.6× / 1.8× 1.0× / 0.7×
ell_Grek 0.58 2.96 2.16 4.54 29.0 23.4 6.0 4.8 13.4× / 6.4× 10.8× / 5.1× 2.8× / 1.3× 2.2× / 1.0×
eng_Latn 0.09 1.45 2.94 4.30 45.6 45.7 11.9 3.8 15.5× / 10.6× 15.5× / 10.6× 4.1× / 2.8× 1.3× / 0.9×
heb_Hebr 1.14 3.01 2.25 4.12 32.3 27.5 6.9 3.0 14.3× / 7.8× 12.2× / 6.7× 3.0× / 1.7× 1.3× / 0.7×
hin_Deva 1.51 3.10 3.06 4.65 64.3 57.8 13.7 4.3 21.0× / 13.8× 18.9× / 12.4× 4.5× / 2.9× 1.4× / 0.9×
jpn_Jpan 1.69 3.36 2.12 3.78 24.1 18.5 5.1 3.8 11.4× / 6.4× 8.7× / 4.9× 2.4× / 1.3× 1.8× / 1.0×
kat_Geor 1.54 2.52 2.07 3.05 17.9 14.9 4.2 2.0 8.6× / 5.9× 7.2× / 4.9× 2.0× / 1.4× 1.0× / 0.6×
kor_Hang 1.22 2.70 2.44 3.91 33.0 29.5 7.5 3.6 13.5× / 8.4× 12.1× / 7.6× 3.1× / 1.9× 1.5× / 0.9×
rus_Cyrl 1.16 2.93 2.09 3.86 28.0 22.6 5.8 2.5 13.4× / 7.3× 10.8× / 5.9× 2.8× / 1.5× 1.2× / 0.6×
tam_Taml 1.11 2.96 2.65 4.49 71.8 62.1 14.5 3.8 27.1× / 16.0× 23.5× / 13.8× 5.5× / 3.2× 1.4× / 0.8×
tha_Thai 1.83 2.53 2.50 3.20 41.4 33.7 8.8 3.2 16.6× / 13.0× 13.5× / 10.5× 3.5× / 2.8× 1.3× / 1.0×
added_normalized_dense 0.06 1.47 1.06 2.47 23.8 23.7 6.3 2.0 22.5× / 9.6× 22.4× / 9.6× 5.9× / 2.5× 1.9× / 0.8×
added_normalized_sparse 0.06 1.48 1.96 3.38 31.7 32.5 8.5 2.7 16.2× / 9.4× 16.6× / 9.6× 4.3× / 2.5× 1.4× / 0.8×
added_special_dense 0.06 1.47 3.97 5.39 95.8 101.7 20.1 2.9 24.1× / 17.8× 25.6× / 18.9× 5.0× / 3.7× 0.7× / 0.5×
added_special_sparse 0.06 1.48 4.15 5.57 61.9 65.8 14.2 3.3 14.9× / 11.1× 15.9× / 11.8× 3.4× / 2.5× 0.8× / 0.6×
agentic-traces 0.75 1.50 3.46 4.21 60.2 63.1 15.7 4.6 17.4× / 14.3× 18.2× / 15.0× 4.5× / 3.7× 1.3× / 1.1×
agentic_swe 0.66 1.49 2.37 3.21 61.2 71.6 14.8 3.5 25.8× / 19.1× 30.2× / 22.3× 6.2× / 4.6× 1.5× / 1.1×
code_mixed 0.07 1.45 2.89 4.27 60.1 69.4 15.2 4.1 20.8× / 14.1× 24.0× / 16.3× 5.2× / 3.6× 1.4× / 1.0×
math_latex 0.74 1.48 3.25 3.98 53.7 54.4 13.9 4.2 16.5× / 13.5× 16.8× / 13.7× 4.3× / 3.5× 1.3× / 1.0×
gpt-oss — o200k-regex byte-level BPE (gpt-oss) · ×19.88 vs v0.23.1 · ×3.93 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 3.8 86.9 ×22.94 ×3.74 7% (0.7) 0% (0.0) 48% (4.7) 47% (4.6) 0% (0.0) match
arb_Arab lang 4.4 93.7 ×21.36 ×5.41 7% (0.6) 0% (0.0) 35% (3.2) 59% (5.3) 0% (0.0) match
ben_Beng lang 6.5 117.6 ×18.16 ×6.71 8% (0.6) 0% (0.0) 49% (3.6) 42% (3.1) 1% (0.1) match
cmn_Hani lang 4.4 107.7 ×24.35 ×8.86 8% (0.6) 0% (0.0) 44% (3.4) 50% (3.8) 0% (0.0) match
ell_Grek lang 4.9 103.0 ×20.85 ×6.48 7% (0.6) 0% (0.0) 39% (3.2) 52% (4.3) 1% (0.1) match
eng_Latn lang 3.9 60.3 ×15.43 ×1.42 14% (2.0) 0% (0.0) 32% (4.5) 55% (7.7) 0% (0.0) match
heb_Hebr lang 4.3 94.4 ×21.86 ×5.69 6% (0.6) 0% (0.0) 36% (3.3) 58% (5.3) 0% (0.0) match
hin_Deva lang 6.7 108.1 ×16.04 ×4.14 8% (0.6) 0% (0.0) 48% (3.7) 45% (3.5) 0% (0.0) match
jpn_Jpan lang 5.3 127.6 ×24.09 ×9.97 9% (0.6) 0% (0.0) 48% (3.1) 41% (2.7) 1% (0.1) match
kat_Geor lang 6.5 134.0 ×20.63 ×9.52 10% (0.6) 0% (0.0) 47% (2.9) 45% (2.8) 0% (0.0) match
kor_Hang lang 3.8 77.3 ×20.35 ×5.05 5% (0.6) 0% (0.0) 32% (3.7) 63% (7.2) 0% (0.0) match
rus_Cyrl lang 4.9 98.5 ×20.06 ×6.30 7% (0.6) 0% (0.0) 38% (3.1) 57% (4.7) 0% (0.0) match
tam_Taml lang 6.7 134.8 ×20.25 ×10.18 10% (0.6) 0% (0.0) 51% (3.2) 39% (2.4) 0% (0.0) match
tha_Thai lang 7.6 158.9 ×20.89 ×13.77 12% (0.6) 0% (0.0) 61% (3.2) 28% (1.5) 0% (0.0) match
added_normalized_dense modalities 5.1 151.9 ×30.01 ×5.99 12% (0.7) 0% (0.0) 37% (2.2) 49% (2.9) 2% (0.1) match
added_normalized_sparse modalities 5.0 112.8 ×22.75 ×2.69 16% (1.3) 0% (0.0) 39% (3.2) 47% (3.8) 0% (0.0) match
added_special_dense modalities 4.1 66.5 ×16.24 ×0.88 36% (5.1) 1% (0.1) 34% (4.8) 31% (4.4) 0% (0.0) match
added_special_sparse modalities 4.2 66.5 ×15.77 ×0.86 22% (3.1) 0% (0.0) 42% (5.8) 36% (5.0) 0% (0.0) match
agentic-traces modalities 3.6 60.2 ×16.55 ×1.57 12% (1.8) 0% (0.0) 33% (5.0) 56% (8.3) 0% (0.0) match
agentic_swe modalities 3.8 74.8 ×19.65 ×2.69 11% (1.3) 0% (0.0) 31% (3.7) 59% (7.1) 0% (0.0) match
code_mixed modalities 3.9 70.4 ×18.08 ×1.39 12% (1.5) 0% (0.0) 35% (4.4) 56% (7.0) 0% (0.0) match
math_latex modalities 3.5 59.0 ×17.00 ×1.53 13% (1.9) 0% (0.0) 32% (4.8) 57% (8.5) 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.78 3.41 4.68 5.31 30.0 14.4 7.0 4.7 6.4× / 5.6× 3.1× / 2.7× 1.5× / 1.3× 1.0× / 0.9×
arb_Arab 1.14 2.99 3.20 5.04 34.4 16.4 7.5 5.1 10.7× / 6.8× 5.1× / 3.3× 2.3× / 1.5× 1.6× / 1.0×
ben_Beng 1.62 3.00 3.64 5.02 24.0 11.4 5.4 2.7 6.6× / 4.8× 3.1× / 2.3× 1.5× / 1.1× 0.7× / 0.5×
cmn_Hani 1.12 2.29 3.37 4.53 21.9 11.0 5.4 2.5 6.5× / 4.8× 3.3× / 2.4× 1.6× / 1.2× 0.7× / 0.5×
ell_Grek 0.58 2.93 3.24 5.59 30.4 15.5 6.8 5.0 9.4× / 5.4× 4.8× / 2.8× 2.1× / 1.2× 1.6× / 0.9×
eng_Latn 0.09 1.46 4.54 5.91 43.3 30.2 13.7 4.2 9.5× / 7.3× 6.6× / 5.1× 3.0× / 2.3× 0.9× / 0.7×
heb_Hebr 1.14 3.06 3.28 5.20 33.8 18.2 8.0 2.9 10.3× / 6.5× 5.6× / 3.5× 2.4× / 1.5× 0.9× / 0.6×
hin_Deva 1.51 3.06 3.71 5.26 26.2 13.0 6.4 3.1 7.0× / 5.0× 3.5× / 2.5× 1.7× / 1.2× 0.8× / 0.6×
jpn_Jpan 1.70 3.34 3.13 4.76 20.5 9.4 4.7 3.9 6.5× / 4.3× 3.0× / 2.0× 1.5× / 1.0× 1.2× / 0.8×
kat_Geor 1.55 2.53 2.92 3.90 19.2 10.3 4.6 2.1 6.6× / 4.9× 3.5× / 2.6× 1.6× / 1.2× 0.7× / 0.5×
kor_Hang 1.22 2.71 3.65 5.14 34.1 19.4 8.9 3.6 9.3× / 6.6× 5.3× / 3.8× 2.4× / 1.7× 1.0× / 0.7×
rus_Cyrl 1.16 2.93 3.13 4.89 29.2 15.3 6.7 4.9 9.3× / 6.0× 4.9× / 3.1× 2.2× / 1.4× 1.6× / 1.0×
tam_Taml 0.93 2.91 3.16 5.14 19.2 9.0 4.2 2.9 6.1× / 3.7× 2.8× / 1.8× 1.3× / 0.8× 0.9× / 0.6×
tha_Thai 1.52 2.57 3.17 4.22 13.2 5.8 2.7 2.2 4.2× / 3.1× 1.8× / 1.4× 0.9× / 0.6× 0.7× / 0.5×
added_normalized_dense 0.06 1.47 2.16 3.57 32.4 18.0 11.2 2.2 15.0× / 9.1× 8.3× / 5.0× 5.2× / 3.1× 1.0× / 0.6×
added_normalized_sparse 0.06 1.47 3.17 4.58 35.0 21.7 11.4 3.0 11.1× / 7.6× 6.8× / 4.7× 3.6× / 2.5× 0.9× / 0.6×
added_special_dense 0.06 1.47 4.84 6.25 84.3 70.9 24.8 3.4 17.4× / 13.5× 14.7× / 11.3× 5.1× / 4.0× 0.7× / 0.5×
added_special_sparse 0.06 1.47 5.82 7.23 56.2 43.1 16.9 3.7 9.7× / 7.8× 7.4× / 6.0× 2.9× / 2.3× 0.6× / 0.5×
agentic-traces 0.72 1.47 4.96 5.71 52.3 43.7 17.4 4.9 10.6× / 9.2× 8.8× / 7.6× 3.5× / 3.1× 1.0× / 0.9×
agentic_swe 0.65 1.56 3.73 4.64 52.8 51.6 17.5 3.6 14.1× / 11.4× 13.8× / 11.1× 4.7× / 3.8× 1.0× / 0.8×
code_mixed 0.06 1.44 4.37 5.75 51.9 48.7 17.5 4.3 11.9× / 9.0× 11.1× / 8.5× 4.0× / 3.0× 1.0× / 0.7×
math_latex 0.75 1.50 4.82 5.57 49.9 37.0 15.9 4.5 10.3× / 8.9× 7.7× / 6.6× 3.3× / 2.8× 0.9× / 0.8×
glm-5.2 — cl100k-variant regex byte-level BPE (glm-5.2) · ×20.77 vs v0.23.1 · ×3.20 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 231) · 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.1 89.2 ×21.75 ×1.85 13% (1.2) 0% (0.0) 41% (3.7) 47% (4.3) 0% (0.0) match
arb_Arab lang 4.4 100.5 ×22.65 ×5.62 14% (1.2) 0% (0.0) 28% (2.3) 59% (5.0) 0% (0.0) match
ben_Beng lang 4.3 106.7 ×25.08 ×4.01 13% (1.2) 0% (0.0) 37% (3.2) 50% (4.4) 0% (0.0) match
cmn_Hani lang 4.8 115.3 ×24.03 ×7.90 16% (1.2) 0% (0.0) 32% (2.4) 48% (3.5) 4% (0.3) match
ell_Grek lang 5.0 108.3 ×21.52 ×5.56 15% (1.2) 0% (0.0) 28% (2.2) 53% (4.3) 5% (0.4) match
eng_Latn lang 3.8 63.6 ×16.65 ×1.43 19% (2.5) 0% (0.0) 23% (3.0) 58% (7.8) 0% (0.0) match
heb_Hebr lang 4.2 101.1 ×24.02 ×3.94 14% (1.2) 0% (0.0) 28% (2.4) 59% (5.0) 0% (0.0) match
hin_Deva lang 3.9 93.2 ×23.65 ×3.12 12% (1.2) 0% (0.0) 33% (3.3) 57% (5.6) 0% (0.0) match
jpn_Jpan lang 5.6 136.1 ×24.53 ×8.75 20% (1.2) 0% (0.0) 37% (2.2) 44% (2.6) 0% (0.0) match
kat_Geor lang 6.3 136.7 ×21.58 ×6.18 19% (1.2) 0% (0.0) 35% (2.1) 45% (2.7) 1% (0.0) match
kor_Hang lang 3.8 84.3 ×22.23 ×4.54 11% (1.2) 0% (0.0) 24% (2.6) 66% (6.9) 0% (0.0) match
rus_Cyrl lang 4.9 102.2 ×20.90 ×5.45 15% (1.2) 0% (0.0) 27% (2.2) 59% (4.7) 0% (0.0) match
tam_Taml lang 3.8 106.1 ×27.65 ×2.99 13% (1.2) 0% (0.0) 32% (2.7) 57% (4.9) 0% (0.0) match
tha_Thai lang 4.8 108.6 ×22.54 ×5.17 15% (1.2) 0% (0.0) 34% (2.6) 53% (4.2) 0% (0.0) match
added_normalized_dense modalities 6.0 167.8 ×28.02 ×6.20 25% (1.3) 0% (0.0) 21% (1.1) 58% (2.9) 0% (0.0) match
added_normalized_sparse modalities 5.4 121.2 ×22.32 ×2.89 24% (1.8) 0% (0.0) 27% (2.0) 49% (3.7) 2% (0.1) match
added_special_dense modalities 4.2 44.4 ×10.69 ×0.94 59% (12.7) 1% (0.3) 24% (5.0) 17% (3.7) 0% (0.0) match
added_special_sparse modalities 4.3 56.9 ×13.14 ×0.99 43% (7.0) 1% (0.1) 30% (4.9) 27% (4.4) 0% (0.0) match
agentic-traces modalities 3.5 63.2 ×18.26 ×1.78 17% (2.5) 0% (0.0) 26% (3.7) 55% (7.9) 2% (0.2) match
agentic_swe modalities 3.7 75.1 ×20.43 ×2.69 17% (1.9) 0% (0.0) 25% (2.9) 59% (6.9) 0% (0.0) match
code_mixed modalities 3.9 72.7 ×18.51 ×1.59 18% (2.2) 0% (0.0) 27% (3.3) 55% (6.7) 0% (0.0) match
math_latex modalities 3.7 62.6 ×17.05 ×1.61 17% (2.5) 0% (0.0) 24% (3.5) 59% (8.4) 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.79 3.41 3.71 4.34 27.6 16.5 5.9 4.8 7.4× / 6.4× 4.5× / 3.8× 1.6× / 1.4× 1.3× / 1.1×
arb_Arab 1.15 2.98 2.34 4.17 31.7 20.3 6.9 5.1 13.5× / 7.6× 8.7× / 4.9× 2.9× / 1.6× 2.2× / 1.2×
ben_Beng 1.61 2.94 3.19 4.52 45.6 28.8 10.3 3.7 14.3× / 10.1× 9.0× / 6.4× 3.2× / 2.3× 1.2× / 0.8×
cmn_Hani 1.12 2.26 2.40 3.54 20.1 11.9 4.7 2.5 8.4× / 5.7× 5.0× / 3.4× 1.9× / 1.3× 1.0× / 0.7×
ell_Grek 0.59 3.00 2.24 4.65 28.6 17.6 6.1 4.7 12.8× / 6.2× 7.9× / 3.8× 2.7× / 1.3× 2.1× / 1.0×
eng_Latn 0.11 1.46 3.04 4.40 44.3 34.1 12.6 3.7 14.6× / 10.1× 11.2× / 7.8× 4.1× / 2.9× 1.2× / 0.8×
heb_Hebr 1.14 3.02 2.36 4.24 31.1 20.5 6.9 3.0 13.2× / 7.3× 8.7× / 4.8× 2.9× / 1.6× 1.3× / 0.7×
hin_Deva 1.52 3.12 3.29 4.89 48.4 31.1 11.3 4.0 14.7× / 9.9× 9.5× / 6.4× 3.4× / 2.3× 1.2× / 0.8×
jpn_Jpan 1.70 3.35 2.21 3.86 18.6 10.1 4.0 3.7 8.4× / 4.8× 4.6× / 2.6× 1.8× / 1.0× 1.7× / 1.0×
kat_Geor 1.54 2.51 2.13 3.09 17.2 11.6 4.2 2.0 8.1× / 5.5× 5.5× / 3.7× 2.0× / 1.3× 0.9× / 0.7×
kor_Hang 1.22 2.70 2.56 4.04 31.5 21.7 7.3 3.6 12.3× / 7.8× 8.5× / 5.4× 2.9× / 1.8× 1.4× / 0.9×
rus_Cyrl 1.16 2.90 2.16 3.90 27.3 17.0 5.9 2.4 12.6× / 7.0× 7.9× / 4.4× 2.7× / 1.5× 1.1× / 0.6×
tam_Taml 0.93 2.95 2.74 4.76 45.0 27.5 9.9 3.4 16.4× / 9.4× 10.0× / 5.8× 3.6× / 2.1× 1.3× / 0.7×
tha_Thai 1.51 2.53 2.64 3.66 28.5 16.7 6.8 3.0 10.8× / 7.8× 6.3× / 4.6× 2.6× / 1.8× 1.1× / 0.8×
added_normalized_dense 0.06 1.47 1.06 2.48 23.5 17.3 6.5 1.8 22.2× / 9.5× 16.4× / 7.0× 6.2× / 2.6× 1.7× / 0.7×
added_normalized_sparse 0.06 1.48 2.03 3.44 31.2 23.4 8.8 2.5 15.4× / 9.1× 11.6× / 6.8× 4.3× / 2.5× 1.2× / 0.7×
added_special_dense 0.06 1.47 5.04 6.46 95.0 76.5 21.2 3.1 18.8× / 14.7× 15.2× / 11.8× 4.2× / 3.3× 0.6× / 0.5×
added_special_sparse 0.06 1.47 4.86 6.27 60.9 46.9 15.0 3.4 12.5× / 9.7× 9.6× / 7.5× 3.1× / 2.4× 0.7× / 0.5×
agentic-traces 0.72 1.53 3.75 4.56 53.3 46.6 15.1 4.5 14.2× / 11.7× 12.4× / 10.2× 4.0× / 3.3× 1.2× / 1.0×
agentic_swe 0.66 1.49 2.90 3.74 54.9 53.1 15.8 3.4 18.9× / 14.7× 18.3× / 14.2× 5.5× / 4.2× 1.2× / 0.9×
code_mixed 0.07 1.44 3.29 4.65 52.6 52.0 15.4 4.0 16.0× / 11.3× 15.8× / 11.2× 4.7× / 3.3× 1.2× / 0.9×
math_latex 0.73 1.54 3.48 4.30 51.3 40.3 14.2 4.1 14.7× / 11.9× 11.6× / 9.4× 4.1× / 3.3× 1.2× / 1.0×
llama-2 — model-bounded BPE, no pre-tokenizer · ×4.05 vs v0.23.1 · ×1.13 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 18+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.7 42.3 ×8.98 ×1.05 0% (0.0) 11% (2.7) 0% (0.1) 88% (21.0) 0% (0.0) match
arb_Arab lang 10.3 49.2 ×4.77 ×1.01 0% (0.0) 16% (3.2) 1% (0.1) 83% (16.7) 0% (0.1) match
ben_Beng lang 11.1 81.1 ×7.34 ×1.07 0% (0.0) 18% (2.1) 1% (0.1) 81% (9.7) 0% (0.1) match
cmn_Hani lang 9.1 64.6 ×7.08 ×1.04 0% (0.1) 3% (0.4) 0% (0.0) 97% (14.4) 0% (0.0) match
ell_Grek lang 10.3 57.6 ×5.56 ×1.04 0% (0.0) 18% (3.1) 1% (0.1) 81% (13.9) 0% (0.1) match
eng_Latn lang 4.1 6.3 ×1.53 ×0.99 0% (0.0) 4% (7.0) 0% (0.2) 96% (151.5) 0% (0.0) match
heb_Hebr lang 10.3 60.2 ×5.83 ×1.03 0% (0.0) 20% (3.3) 1% (0.1) 79% (13.0) 0% (0.0) match
hin_Deva lang 12.3 79.4 ×6.47 ×1.08 0% (0.0) 23% (2.8) 1% (0.1) 76% (9.3) 0% (0.0) match
jpn_Jpan lang 12.9 83.7 ×6.50 ×1.05 0% (0.1) 3% (0.4) 0% (0.0) 97% (10.9) 0% (0.0) match
kat_Geor lang 14.4 89.5 ×6.22 ×1.06 0% (0.1) 18% (1.9) 1% (0.1) 81% (8.7) 0% (0.0) match
kor_Hang lang 7.3 50.9 ×6.95 ×1.02 0% (0.1) 17% (3.3) 1% (0.1) 82% (15.8) 0% (0.0) match
rus_Cyrl lang 7.9 16.0 ×2.03 ×1.00 0% (0.0) 5% (2.8) 0% (0.2) 95% (59.2) 0% (0.0) match
tam_Taml lang 12.7 89.6 ×7.05 ×1.08 0% (0.0) 16% (1.8) 0% (0.1) 83% (9.0) 0% (0.0) match
tha_Thai lang 15.6 84.5 ×5.43 ×1.03 0% (0.0) 9% (1.0) 0% (0.0) 90% (10.3) 0% (0.0) match
added_normalized_dense modalities 5.5 8.7 ×1.59 ×0.99 0% (0.0) 3% (3.8) 0% (0.1) 97% (112.4) 0% (0.0) match
added_normalized_sparse modalities 4.7 7.4 ×1.57 ×1.00 0% (0.0) 5% (6.2) 0% (0.2) 95% (127.6) 0% (0.3) match
added_special_dense modalities 3.8 39.0 ×10.25 ×1.94 21% (5.2) 63% (15.3) 5% (1.3) 11% (2.6) 0% (0.1) match
added_special_sparse modalities 5.3 45.5 ×8.55 ×4.44 12% (2.1) 77% (14.2) 3% (0.5) 9% (1.7) 0% (0.0) match
agentic-traces modalities 4.4 7.0 ×1.59 ×0.99 0% (0.1) 4% (6.2) 0% (0.2) 95% (135.4) 0% (0.2) match
agentic_swe modalities 4.0 6.9 ×1.72 ×0.99 0% (0.0) 7% (9.7) 0% (0.2) 93% (134.7) 0% (0.5) match
code_mixed modalities 4.2 6.9 ×1.64 ×0.98 0% (0.0) 5% (8.0) 0% (0.3) 94% (136.5) 0% (0.0) match
math_latex modalities 4.3 6.6 ×1.54 ×0.98 0% (0.1) 4% (6.5) 0% (0.2) 95% (143.2) 0% (0.1) match
llama-3 — cl100k-regex byte-level BPE (llama-3), single regex · ×21.96 vs v0.23.1 · ×3.09 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 95)

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.4 ×21.72 ×1.95 8% (0.7) 0% (0.0) 43% (3.7) 50% (4.3) 0% (0.0) match
arb_Arab lang 4.5 105.3 ×23.40 ×5.88 7% (0.6) 0% (0.0) 29% (2.3) 67% (5.4) 0% (0.0) match
ben_Beng lang 4.2 109.4 ×26.29 ×3.49 7% (0.6) 0% (0.0) 37% (3.1) 56% (4.7) 0% (0.0) match
cmn_Hani lang 5.0 125.4 ×24.92 ×7.50 9% (0.6) 0% (0.0) 37% (2.4) 52% (3.5) 2% (0.1) match
ell_Grek lang 5.2 117.2 ×22.37 ×6.07 8% (0.6) 0% (0.0) 31% (2.2) 60% (4.3) 1% (0.1) match
eng_Latn lang 4.2 67.2 ×15.92 ×1.45 16% (2.0) 0% (0.0) 25% (3.0) 60% (7.4) 0% (0.0) match
heb_Hebr lang 4.2 107.5 ×25.74 ×4.14 8% (0.6) 0% (0.0) 30% (2.3) 63% (4.9) 0% (0.0) match
hin_Deva lang 4.3 99.7 ×23.24 ×1.30 6% (0.6) 0% (0.0) 36% (3.3) 59% (5.5) 0% (0.0) match
jpn_Jpan lang 5.6 147.5 ×26.24 ×9.09 11% (0.6) 0% (0.0) 41% (2.2) 50% (2.7) 0% (0.0) match
kat_Geor lang 5.6 143.4 ×25.41 ×3.87 11% (0.6) 0% (0.0) 38% (2.1) 52% (2.9) 0% (0.0) match
kor_Hang lang 3.9 85.8 ×22.05 ×4.49 6% (0.6) 0% (0.0) 25% (2.5) 69% (6.9) 0% (0.0) match
rus_Cyrl lang 4.8 113.6 ×23.69 ×6.94 8% (0.6) 0% (0.0) 30% (2.2) 62% (4.5) 0% (0.0) match
tam_Taml lang 3.9 111.9 ×28.40 ×3.15 7% (0.6) 0% (0.0) 34% (2.7) 60% (4.9) 0% (0.0) match
tha_Thai lang 5.0 110.1 ×21.88 ×5.42 8% (0.6) 0% (0.0) 34% (2.6) 57% (4.3) 1% (0.1) match
added_normalized_dense modalities 6.1 182.7 ×29.99 ×6.73 16% (0.7) 0% (0.0) 25% (1.2) 58% (2.7) 1% (0.1) match
added_normalized_sparse modalities 5.6 130.7 ×23.44 ×3.07 18% (1.3) 0% (0.0) 27% (1.9) 53% (3.7) 2% (0.1) match
added_special_dense modalities 4.2 65.8 ×15.74 ×0.87 36% (5.0) 0% (0.0) 35% (4.7) 29% (3.9) 0% (0.0) match
added_special_sparse modalities 4.4 70.8 ×16.26 ×0.98 25% (3.1) 0% (0.1) 38% (4.8) 38% (4.7) 0% (0.0) match
agentic-traces modalities 3.6 65.2 ×18.31 ×1.74 13% (1.8) 0% (0.0) 28% (3.7) 58% (7.8) 1% (0.1) match
agentic_swe modalities 4.0 80.9 ×20.01 ×2.85 12% (1.3) 0% (0.0) 27% (2.9) 65% (6.9) 0% (0.0) match
code_mixed modalities 4.1 77.4 ×18.80 ×1.64 14% (1.5) 0% (0.0) 29% (3.3) 58% (6.6) 0% (0.0) match
math_latex modalities 3.8 65.0 ×17.31 ×1.59 14% (1.9) 0% (0.0) 26% (3.5) 60% (7.9) 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.79 3.39 3.71 4.31 27.2 16.7 5.9 4.8 7.3× / 6.3× 4.5× / 3.9× 1.6× / 1.4× 1.3× / 1.1×
arb_Arab 1.17 2.98 2.33 4.14 31.2 19.8 6.9 5.1 13.4× / 7.5× 8.5× / 4.8× 3.0× / 1.7× 2.2× / 1.2×
ben_Beng 1.63 3.01 3.15 4.52 45.5 28.8 10.5 3.7 14.5× / 10.1× 9.1× / 6.4× 3.3× / 2.3× 1.2× / 0.8×
cmn_Hani 1.13 2.24 2.41 3.52 20.0 11.8 4.7 2.4 8.3× / 5.7× 4.9× / 3.4× 1.9× / 1.3× 1.0× / 0.7×
ell_Grek 0.60 2.95 2.19 4.54 28.7 17.5 6.3 4.8 13.1× / 6.3× 8.0× / 3.8× 2.9× / 1.4× 2.2× / 1.0×
eng_Latn 0.11 1.46 3.04 4.40 44.4 34.8 13.0 3.7 14.6× / 10.1× 11.4× / 7.9× 4.3× / 3.0× 1.2× / 0.8×
heb_Hebr 1.16 3.04 2.33 4.21 30.9 20.3 7.0 3.0 13.3× / 7.4× 8.7× / 4.8× 3.0× / 1.7× 1.3× / 0.7×
hin_Deva 1.55 3.10 3.29 4.84 48.2 31.8 11.8 4.0 14.7× / 10.0× 9.7× / 6.6× 3.6× / 2.4× 1.2× / 0.8×
jpn_Jpan 1.70 3.36 2.20 3.86 18.5 10.0 4.1 3.8 8.4× / 4.8× 4.5× / 2.6× 1.8× / 1.1× 1.7× / 1.0×
kat_Geor 1.57 2.56 2.11 3.10 17.2 11.4 4.1 2.0 8.1× / 5.5× 5.4× / 3.7× 2.0× / 1.3× 1.0× / 0.7×
kor_Hang 1.23 2.69 2.52 3.97 31.7 21.8 7.6 3.7 12.6× / 8.0× 8.7× / 5.5× 3.0× / 1.9× 1.5× / 0.9×
rus_Cyrl 1.18 2.91 2.17 3.90 27.3 17.0 5.9 2.5 12.6× / 7.0× 7.9× / 4.4× 2.7× / 1.5× 1.2× / 0.6×
tam_Taml 0.96 2.92 2.73 4.69 45.0 27.5 10.1 3.4 16.5× / 9.6× 10.1× / 5.9× 3.7× / 2.1× 1.3× / 0.7×
tha_Thai 1.55 2.57 2.62 3.65 28.1 16.4 6.7 3.0 10.7× / 7.7× 6.3× / 4.5× 2.6× / 1.8× 1.2× / 0.8×
added_normalized_dense 0.06 1.48 1.15 2.57 23.0 17.5 6.6 1.8 20.0× / 8.9× 15.2× / 6.8× 5.7× / 2.6× 1.5× / 0.7×
added_normalized_sparse 0.06 1.47 1.90 3.31 31.2 23.2 8.5 2.5 16.4× / 9.4× 12.2× / 7.0× 4.5× / 2.6× 1.3× / 0.8×
added_special_dense 0.06 1.47 4.70 6.12 94.7 74.8 21.1 3.1 20.1× / 15.5× 15.9× / 12.2× 4.5× / 3.4× 0.7× / 0.5×
added_special_sparse 0.06 1.47 4.81 6.22 61.1 46.4 15.1 3.4 12.7× / 9.8× 9.7× / 7.5× 3.1× / 2.4× 0.7× / 0.5×
agentic-traces 0.74 1.47 3.73 4.46 52.4 45.8 15.2 4.6 14.0× / 11.7× 12.3× / 10.3× 4.1× / 3.4× 1.2× / 1.0×
agentic_swe 0.68 1.44 2.87 3.63 55.0 54.0 15.7 3.4 19.1× / 15.2× 18.8× / 14.9× 5.5× / 4.3× 1.2× / 0.9×
code_mixed 0.10 1.44 3.31 4.66 52.8 51.2 15.4 4.0 15.9× / 11.3× 15.5× / 11.0× 4.7× / 3.3× 1.2× / 0.9×
math_latex 0.79 1.48 3.49 4.18 51.2 40.1 14.2 4.1 14.7× / 12.3× 11.5× / 9.6× 4.1× / 3.4× 1.2× / 1.0×
mistral-small-4 — tekken byte-level BPE, 1k added specials (mistral-small-4) · ×7.71 vs v0.23.1 · ×2.15 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 108+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.6 42.4 ×11.88 ×1.40 6% (1.2) 0% (0.0) 71% (14.8) 23% (4.8) 0% (0.0) match
arb_Arab lang 4.4 38.9 ×8.77 ×2.26 5% (1.2) 0% (0.0) 71% (16.9) 24% (5.8) 0% (0.0) match
ben_Beng lang 6.5 60.0 ×9.20 ×3.49 7% (1.2) 0% (0.0) 71% (11.2) 22% (3.5) 0% (0.0) match
cmn_Hani lang 4.7 53.0 ×11.36 ×3.41 7% (1.2) 0% (0.0) 68% (11.9) 23% (4.0) 2% (0.4) match
ell_Grek lang 5.0 43.6 ×8.66 ×2.84 5% (1.2) 0% (0.0) 72% (15.8) 22% (4.9) 0% (0.1) match
eng_Latn lang 3.8 22.7 ×6.04 ×1.19 6% (2.5) 0% (0.0) 73% (31.0) 22% (9.5) 0% (0.0) match
heb_Hebr lang 4.1 39.0 ×9.41 ×2.79 5% (1.2) 0% (0.0) 73% (18.0) 23% (5.7) 0% (0.0) match
hin_Deva lang 6.4 51.8 ×8.13 ×2.41 6% (1.2) 0% (0.0) 72% (13.2) 22% (4.0) 0% (0.0) match
jpn_Jpan lang 5.4 65.3 ×12.19 ×4.29 8% (1.2) 0% (0.0) 69% (9.9) 23% (3.2) 1% (0.1) match
kat_Geor lang 6.3 63.4 ×10.04 ×4.45 8% (1.2) 0% (0.0) 71% (10.5) 21% (3.1) 0% (0.0) match
kor_Hang lang 3.8 33.1 ×8.81 ×2.19 4% (1.2) 0% (0.0) 68% (19.8) 27% (7.7) 1% (0.3) match
rus_Cyrl lang 4.6 43.3 ×9.40 ×3.04 5% (1.2) 0% (0.0) 71% (15.5) 26% (5.7) 0% (0.0) match
tam_Taml lang 6.6 72.8 ×11.11 ×5.00 9% (1.2) 0% (0.0) 70% (9.1) 21% (2.7) 0% (0.0) match
tha_Thai lang 7.9 103.6 ×13.16 ×6.85 13% (1.2) 0% (0.0) 68% (5.9) 18% (1.6) 1% (0.1) match
added_normalized_dense modalities 5.8 43.8 ×7.59 ×2.13 6% (1.3) 0% (0.0) 81% (17.9) 13% (2.8) 1% (0.2) match
added_normalized_sparse modalities 5.5 35.7 ×6.49 ×1.44 7% (1.9) 0% (0.0) 78% (21.2) 15% (4.1) 0% (0.0) match
added_special_dense modalities 4.3 16.0 ×3.74 ×0.96 8% (5.2) 0% (0.1) 82% (51.1) 9% (5.6) 1% (0.5) match
added_special_sparse modalities 4.6 21.3 ×4.66 ×0.97 8% (3.6) 0% (0.0) 79% (35.9) 13% (5.8) 1% (0.3) match
agentic-traces modalities 3.3 17.3 ×5.23 ×1.16 4% (2.4) 0% (0.0) 77% (44.0) 19% (10.8) 0% (0.1) match
agentic_swe modalities 3.4 15.1 ×4.49 ×1.35 3% (1.9) 0% (0.0) 82% (54.3) 15% (9.7) 1% (0.7) match
code_mixed modalities 3.6 16.8 ×4.61 ×1.13 5% (3.2) 0% (0.0) 81% (48.8) 16% (9.4) 0% (0.0) match
math_latex modalities 3.5 19.2 ×5.44 ×1.11 5% (2.5) 0% (0.0) 75% (38.5) 20% (10.0) 0% (0.1) 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.78 3.43 14.78 15.43 28.8 14.6 6.7 1.9× / 1.9× 1.0× / 0.9× 0.5× / 0.4×
arb_Arab 1.15 2.99 16.91 18.76 32.9 16.5 7.2 1.9× / 1.8× 1.0× / 0.9× 0.4× / 0.4×
ben_Beng 1.62 2.89 11.21 12.48 23.0 11.0 5.2 2.1× / 1.8× 1.0× / 0.9× 0.5× / 0.4×
cmn_Hani 1.11 2.25 11.87 13.01 21.8 11.6 5.5 1.8× / 1.7× 1.0× / 0.9× 0.5× / 0.4×
ell_Grek 0.58 3.01 15.75 18.18 28.9 15.5 6.6 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
eng_Latn 0.09 1.45 31.00 32.36 41.7 31.0 13.4 1.3× / 1.3× 1.0× / 1.0× 0.4× / 0.4×
heb_Hebr 1.14 3.05 18.01 19.92 32.3 18.0 7.7 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
hin_Deva 1.51 3.10 13.21 14.80 25.0 13.4 6.0 1.9× / 1.7× 1.0× / 0.9× 0.5× / 0.4×
jpn_Jpan 1.69 3.38 9.85 11.54 20.4 9.7 4.9 2.1× / 1.8× 1.0× / 0.8× 0.5× / 0.4×
kat_Geor 1.55 2.51 10.50 11.46 18.6 10.4 4.4 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
kor_Hang 1.23 2.69 19.77 21.23 32.8 19.8 8.7 1.7× / 1.5× 1.0× / 0.9× 0.4× / 0.4×
rus_Cyrl 1.16 2.92 15.47 17.23 28.0 15.4 6.3 1.8× / 1.6× 1.0× / 0.9× 0.4× / 0.4×
tam_Taml 0.93 2.89 9.07 11.03 18.7 8.9 4.2 2.1× / 1.7× 1.0× / 0.8× 0.5× / 0.4×
tha_Thai 1.51 2.60 5.94 7.03 13.3 5.9 2.8 2.2× / 1.9× 1.0× / 0.8× 0.5× / 0.4×
added_normalized_dense 0.24 1.47 17.93 19.16 30.4 17.8 11.3 1.7× / 1.6× 1.0× / 0.9× 0.6× / 0.6×
added_normalized_sparse 0.25 1.47 21.19 22.42 32.4 20.8 11.1 1.5× / 1.4× 1.0× / 0.9× 0.5× / 0.5×
added_special_dense 0.24 1.47 51.13 52.36 82.9 69.1 23.5 1.6× / 1.6× 1.4× / 1.3× 0.5× / 0.4×
added_special_sparse 0.24 1.47 35.93 37.16 53.8 42.4 16.4 1.5× / 1.4× 1.2× / 1.1× 0.5× / 0.4×
agentic-traces 0.74 1.55 44.03 44.84 52.1 44.7 16.9 1.2× / 1.2× 1.0× / 1.0× 0.4× / 0.4×
agentic_swe 0.66 1.47 54.32 55.13 56.9 56.2 26.8 1.0× / 1.0× 1.0× / 1.0× 0.5× / 0.5×
code_mixed 0.07 1.48 48.83 50.24 51.7 50.2 17.4 1.1× / 1.0× 1.0× / 1.0× 0.4× / 0.3×
math_latex 0.71 1.48 38.51 39.27 49.5 38.2 15.7 1.3× / 1.3× 1.0× / 1.0× 0.4× / 0.4×
Not yet supported: t5-base
t5-base not supported

Replaces the 4-way set-associative table with an open-addressed one that makes
room by overwriting rather than by rebuilding.

Two things drove it, both measured in cache_bench on 3 models x 18 corpora:
the 4-way table locks ~0.4% of words out on bucket conflicts that open
addressing simply does not have, and the alternative that fixes that (PR #2234's
FlatCache) can only reclaim arena space by compacting every live entry into a
second set of buffers -- so it carries two of everything, 12.6 MB per instance
against this one's 2.7 MB.

Nothing here needs a second copy:

- Eviction overwrites a slot in place. Slots go empty -> occupied and never
  back, so a probe walk is never cut short by a hole and there are no tombstones
  and no backward shift. The cost is that the walk needs a bound, hence WINDOW.
- Slots are self-contained at 32 B, two to a cache line. A <= 15-byte word packs
  into the u128 key, so a hit is a register compare with no memcmp and no key
  arena; up to 3 ids ride in the slot, so most hits never touch the id arena
  either.
- What still needs an arena takes a run from a free list per exact length
  (MAX_LENGTH bounds every run, so there is no rounding waste), and gives it
  back on eviction. The arenas therefore hold the live set instead of every
  insert, and never need compacting.

Retention is FlatCache's idea made local: a full window evicts its coldest slot
and halves the frequencies it passed, so an entry has to keep being used to keep
its place.

Measured against the 4-way it replaces, at the shipped 65,536 capacity: 0.000%
steady-state miss rate against 0.413%, and x1.12 median warm replay across the
54 model x corpus pairs. Against FlatCache it is a near-tie on speed (x0.97) for
22% of the memory, and x11.6 ahead on the one corpus where FlatCache's arena
budget forces it to cull.

`get` now takes &mut self: it bumps the entry's frequency and unpacks inline ids
into a scratch field to hand back a slice. The one call site already held a &mut
binding, so it needed no change.
@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.

Comment thread tokenizers/tk-encode/src/models/bpe/word_cache.rs Outdated
Co-authored-by: Simon Brandeis <33657802+SBrandeis@users.noreply.github.com>
@SBrandeis SBrandeis changed the title WordCache: one generation, evicting in place WordCache: FlatCache tricks Jul 28, 2026
@SBrandeis
SBrandeis marked this pull request as ready for review July 29, 2026 12:02
@SBrandeis
SBrandeis merged commit cd91d69 into feat/bpe-cache Jul 29, 2026
52 of 56 checks passed
@SBrandeis
SBrandeis deleted the feat/flat-inplace-cache branch July 29, 2026 12:02
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