Pack mixed-width UTF-32 blocks from width/error masks instead of scalarizing them
perfloop/simdutf · Data-Parallel Gap
https://perfloop.ai/t/oss/case_nqbvgjwvc2
Verdict
VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-14
What happened: The paired measurements met the required improvement.
Hypothesis
The public entry in `src/implementation.cpp` forwards through the selected implementation, and the fallback hop in `src/fallback/implementation.cpp` immediately hands the entire buffer to `scalar::utf32_to_utf8::convert_with_errors`; that leaf has only a two-code-point ASCII check before its per-code-point width branches, error checks, and byte stores. This is broader than the published ASCII widening: mixed 1/2/3/4-byte input still takes the scalar shape, and the ISA sources expose the same structural bailout—`src/haswell/avx2_convert_utf32_to_utf8.cpp` falls into a scalar loop when a block contains a value above `0xFFFF`—despite the existing width-keyed packing tables in `src/tables/utf16_to_utf8_tables.h`. Carrying a compact width/error plan across the entry, dispatch, and leaf would remove that per-code-point branch-and-bailout class for valid mixed and non-BMP blocks; the remaining floor would be block loads, classification/validation, packed stores, and scalar work only for a tail or the first failing block. A later case should falsify this with an end-to-end, forced-fallback and per-ISA `convert_utf32_to_utf8_with_errors` benchmark using exact-size output buffers and ASCII, mixed-width, emoji-heavy, and every-lane error-position inputs, checking cycles per input scalar and latency alongside exact output and `result` semantics; reject the change if mixed/non-BMP cases do not improve without an ASCII regression.
Change to test: Introduce a shared internal block-transcode contract selected once by `convert_utf32_to_utf8_with_errors`: classify each 4- or 8-code-point block into a 2-bit UTF-8-width plan plus an invalid-lane mask, use a 1/2/3/4-byte packing table or backend vector-compress primitive to emit an all-valid mixed block, and scalarize only the prefix of the one block containing the first invalid lane. Route the public entry, implementation dispatch, fallback implementation, and ISA backends through that contract; retain the already-published widened ASCII route as an earlier fast path and preserve the exact error code and input index.
Where it lives
perfloop/simdutf · src/implementation.cpp
Evidence
Haswell UTF-32 text conversion · 17 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
lipsum/Emoji-Lipsum plain ns/call |
29298 |
7443 |
−74.6% (−21857) |
−21897 to −21846 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
lipsum/Emoji-Lipsum with-errors ns/call |
39667 |
7740 |
−80.5% (−31926) |
−31947 to −30774 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
emoji names plain ns/call |
1510 |
1358 |
−10.1% (−153.2) |
−184.3 to −90.7 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
emoji names with-errors ns/call |
1437 |
1386 |
−43.6 |
−106.8 to +3.2 |
loss ≤ 0.05 × |baseline median| |
PASSED |
all-width mixed plain ns/call |
212096 |
47358 |
−77.7% (−164715) |
−167079 to −163767 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
all-width mixed with-errors ns/call |
198570 |
47190 |
−76.2% (−151297) |
−152765 to −149863 |
gain > 0; gain > 0.05 × |baseline median|; arm medians separated |
PASSED |
Haswell UTF-32 text conversion · 17 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
lipsum/Arabic-Lipsum plain ns/call |
15068 |
14737 |
−299 |
−687 to +80 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Arabic-Lipsum with-errors ns/call |
15754 |
15753 |
−14 |
−278 to +338 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Chinese-Lipsum plain ns/call |
11147 |
10916 |
−2% (−228) |
−473 to −27 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Chinese-Lipsum with-errors ns/call |
11660 |
11821 |
+139 |
−85 to +334 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Hebrew-Lipsum plain ns/call |
12265 |
12028 |
−232 |
−524 to +31 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Hebrew-Lipsum with-errors ns/call |
12831 |
12875 |
−12 |
−231 to +374 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Hindi-Lipsum plain ns/call |
15642 |
15438 |
−1.3% (−202) |
−414 to −38 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Hindi-Lipsum with-errors ns/call |
16488 |
16734 |
+1.8% (+293) |
+122 to +405 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 17 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
lipsum/Japanese-Lipsum plain ns/call |
11080 |
10889 |
−182 |
−448 to +144 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Japanese-Lipsum with-errors ns/call |
11517 |
11743 |
+235 |
−24 to +558 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Korean-Lipsum plain ns/call |
13106 |
12919 |
−186 |
−388 to +37 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Korean-Lipsum with-errors ns/call |
13630 |
13909 |
+2.1% (+286) |
+128 to +539 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Latin-Lipsum plain ns/call |
8742 |
8425 |
−3.6% (−316) |
−497 to −241 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Latin-Lipsum with-errors ns/call |
11568 |
7447 |
−35.6% (−4121) |
−4123 to −4118 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Russian-Lipsum plain ns/call |
18983 |
18717 |
−267 |
−775 to +173 |
loss ≤ 0.05 × |baseline median| |
PASSED |
lipsum/Russian-Lipsum with-errors ns/call |
19906 |
20014 |
+87 |
−459 to +432 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 136 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/arabic plain ns/call |
129341 |
129071 |
−365 |
−2724 to +2534 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/arabic with-errors ns/call |
136996 |
139569 |
+1.6% (+2191) |
+328 to +4722 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/chinese plain ns/call |
35958 |
36018 |
+30 |
−106 to +171 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/chinese with-errors ns/call |
39270 |
41367 |
+5.4% (+2114) |
+1870 to +2300 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/czech plain ns/call |
31883 |
31830 |
−72.5 |
−377 to +266 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/czech with-errors ns/call |
35382 |
36647 |
+3.4% (+1220) |
+882 to +1564 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/english plain ns/call |
56003 |
56165 |
−155.5 |
−2264 to +2652 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/english with-errors ns/call |
66399 |
66833 |
+651.5 |
−2099 to +2993 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 93 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/esperanto plain ns/call |
13440 |
13328 |
−0.9% (−116) |
−219 to −29 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/esperanto with-errors ns/call |
15246 |
15729 |
+3.1% (+475) |
+399 to +545 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/french plain ns/call |
152708 |
151990 |
−1235 |
−4655 to +1726 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/french with-errors ns/call |
163993 |
161221 |
−1.6% (−2560) |
−4798 to −760 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/german plain ns/call |
31194 |
32416 |
+3.8% (+1173) |
+1000 to +1543 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/german with-errors ns/call |
35853 |
39530 |
+10.2% (+3654) |
+3172 to +4140 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/greek plain ns/call |
31086 |
31061 |
+46 |
−311 to +311 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/greek with-errors ns/call |
34424 |
35042 |
+1.8% (+623) |
+373 to +863 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 32 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/hebrew plain ns/call |
35762 |
35932 |
+362 |
−574 to +910 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/hebrew with-errors ns/call |
38843 |
40070 |
+3% (+1157) |
+489 to +1905 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/hindi plain ns/call |
75846 |
81812 |
+7.8% (+5921) |
+3049 to +8686 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/hindi with-errors ns/call |
82673 |
91904 |
+11.4% (+9448) |
+6872 to +11772 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/japanese plain ns/call |
31492 |
31369 |
−132.5 |
−359 to +110 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/japanese with-errors ns/call |
34333 |
35511 |
+3.3% (+1126) |
+894 to +1618 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/korean plain ns/call |
20480 |
20165 |
−1.6% (−323) |
−618 to −141 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/korean with-errors ns/call |
22202 |
22465 |
+1.1% (+243) |
+4 to +444 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 104 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/persan plain ns/call |
28479 |
28115 |
−1.2% (−329) |
−520 to −206 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/persan with-errors ns/call |
31207 |
31221 |
+29.5 |
−121 to +121 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/portuguese plain ns/call |
62376 |
65697 |
+5.2% (+3239) |
+1652 to +4771 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/portuguese with-errors ns/call |
70831 |
73718 |
+2490 |
−671 to +4580 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
wikipedia_mars/russian plain ns/call |
94458 |
90152 |
−4.7% (−4445) |
−6046 to −2567 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/russian with-errors ns/call |
100780 |
98051 |
−2.8% (−2862) |
−4159 to −1465 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/thai plain ns/call |
125134 |
128635 |
+2.9% (+3591) |
+608 to +6151 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/thai with-errors ns/call |
132618 |
144546 |
+9% (+11997) |
+9637 to +14244 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 36 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/turkish plain ns/call |
41622 |
39144 |
−5.2% (−2181) |
−3899 to −754 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/turkish with-errors ns/call |
45516 |
45837 |
+275 |
−909 to +1438 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 18 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
wikipedia_mars/vietnamese plain ns/call |
113631 |
96073 |
−15.1% (−17148) |
−21228 to −11584 |
loss ≤ 0.05 × |baseline median| |
PASSED |
wikipedia_mars/vietnamese with-errors ns/call |
115604 |
109205 |
−5.6% (−6480) |
−10018 to −2865 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short mixed plain ns/call |
173.2 |
42.2 |
−75.6% (−130.9) |
−132 to −130.4 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short mixed with-errors ns/call |
37.8 |
41.8 |
+10.8% (+4.1) |
+3.4 to +8.1 |
loss ≤ stated 0.35 × |baseline median| |
PASSED |
short sparse plain ns/call |
158.2 |
22.4 |
−85.8% (−135.7) |
−137.2 to −134.9 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short sparse with-errors ns/call |
21.65 |
19.4 |
−11.1% (−2.4) |
−4.2 to −1.4 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 text conversion · 18 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
short ASCII plain ns/call |
153.4 |
12.8 |
−91.6% (−140.5) |
−143.3 to −140.1 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short ASCII with-errors ns/call |
12.8 |
4.3 |
−66.4% (−8.5) |
−9.1 to −8.2 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short four-byte plain ns/call |
202.4 |
34.05 |
−83.1% (−168.2) |
−171 to −160.4 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short four-byte with-errors ns/call |
66.3 |
34.6 |
−47.4% (−31.45) |
−34 to −21.7 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short ASCII half plain ns/call |
166.5 |
23.5 |
−85.9% (−143) |
−144.3 to −142.6 |
loss ≤ 0.05 × |baseline median| |
PASSED |
short ASCII half with-errors ns/call |
28 |
22.7 |
−18.9% (−5.3) |
−8.3 to −4.2 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Haswell UTF-32 boundary conversion · 189 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
tail 0 plain ns/call |
2.702 |
2.198 |
−18% (−0.4869) |
−0.591 to −0.4173 |
loss ≤ 0.05 × |baseline median| |
PASSED |
tail 0 with-errors ns/call |
2.515 |
1.878 |
−25% (−0.6294) |
−0.6776 to −0.6005 |
loss ≤ 0.05 × |baseline median| |
PASSED |
tail 1 plain ns/call |
141.1 |
5.28 |
−95.6% (−134.9) |
−140.7 to −131.1 |
loss ≤ 0.05 × |baseline median| |
PASSED |
tail 1 with-errors ns/call |
5.349 |
5.032 |
−6.2% (−0.33) |
−0.4613 to −0.1796 |
loss ≤ 0.05 × |baseline median| |
PASSED |
tail 27 plain ns/call |
186.2 |
50.96 |
−72.1% (−134.3) |
−137.7 to −130.8 |
loss ≤ 0.05 × |baseline median| |
PASSED |
tail 27 with-errors ns/call |
50.6 |
50.27 |
−0.2464 |
−0.9222 to +0.9101 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 surrogate 0 plain ns/call |
4.969 |
6.27 |
+27.1% (+1.345) |
+1.217 to +1.471 |
loss ≤ stated 0.75 × |baseline median| |
PASSED |
error28 surrogate 0 with-errors ns/call |
7.487 |
8.162 |
+9% (+0.6708) |
+0.5744 to +0.81 |
loss ≤ stated 0.5 × |baseline median| |
PASSED |
error28 too-large 0 plain ns/call |
5.011 |
5.305 |
+6.1% (+0.3055) |
+0.2351 to +0.3844 |
loss ≤ stated 0.5 × |baseline median| |
PASSED |
error28 too-large 0 with-errors ns/call |
5.622 |
5.647 |
+0.02163 |
−0.04312 to +0.1144 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 surrogate 16 plain ns/call |
168.9 |
26.03 |
−84.1% (−142) |
−147.7 to −139.7 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 surrogate 16 with-errors ns/call |
24.32 |
25.35 |
+5.6% (+1.356) |
+0.7454 to +1.963 |
loss ≤ stated 0.5 × |baseline median| |
PASSED |
error28 too-large 16 plain ns/call |
169.1 |
25.49 |
−84.3% (−142.6) |
−148 to −140 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 too-large 16 with-errors ns/call |
25.5 |
25.29 |
+0.04876 |
−0.689 to +0.5433 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 surrogate 27 plain ns/call |
187 |
40.33 |
−78.2% (−146.3) |
−151.4 to −143.9 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 surrogate 27 with-errors ns/call |
39.3 |
39.98 |
+0.8934 |
−0.004485 to +1.93 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 too-large 27 plain ns/call |
189.3 |
40.06 |
−78.5% (−148.6) |
−154.1 to −145.1 |
loss ≤ 0.05 × |baseline median| |
PASSED |
error28 too-large 27 with-errors ns/call |
39.3 |
40.01 |
+2.3% (+0.9193) |
+0.1438 to +1.767 |
loss ≤ 0.05 × |baseline median| |
PASSED |
Checks: 5 of 5 passed. Verification: no defect found.
Timeline
2026-07-31· Case opened2026-08-04· PR opened