Replace carry-chained 64-byte UTF-8 scans with boundary-summary block batches

perfloop/simdjson · Data-Parallel Gap

https://perfloop.ai/t/oss/case_pg5w1h5y4k

Verdict

VALIDATED BY A DIFFERENT CHANGE · settled 2026-11-05

What happened: The paired measurements met the required improvement.

Hypothesis

The traced Ice Lake entry forwards directly into the char overload and then `generic_validate_utf8<utf8_checker>`; that leaf walks `buf_block_reader<64>` one block at a time, calls `check_next_input`, advances, and finishes with a padded remainder plus `check_eof`. In the source, `utf8_checker` carries both `prev_input_block` and `prev_incomplete` from each block to the next, while its actual byte rules use only `prev<1>`, `prev<2>`, and `prev<3>`; on Ice Lake `simd8x64` is one 64-byte register. A boundary-summary layout can therefore remove the long loop-carried validation stage across the entry-to-leaf operation: all block interiors become independent vector work, and only the constant-size windows straddling each 64-byte join and the final EOF state need reduction. The floor remains a compulsory read of every input byte and an O(block-count) boundary reduction, so this is not a claim that standalone UTF-8 validation ceases to be linear or that it will help once memory bandwidth dominates. A later case should falsify the move with a pinned-Ice-Lake end-to-end `validate_utf8` cycles-per-byte and throughput comparison on long ASCII, multilingual valid, and deliberately malformed boundary-spanning inputs, with memory-bandwidth counters and differential fuzzing against the fallback implementation; reject it if the new batching does not reduce the measured compute-side cost before the workload reaches its read-bandwidth floor or changes any validity result.

Change to test: Add an internal bulk-validation path selected by `icelake::implementation::validate_utf8` for sufficiently long inputs: the char overload forwards one pointer/length request to a generic block-batch validator, which validates the interior of each 64-byte chunk independently, retains only a compact three-byte prefix/suffix and error summary per chunk, then reduces adjacent boundary summaries and the single EOF summary. Mask the first three lanes of each independent chunk and validate the cross-chunk windows in the boundary reduction, because UTF-8 rules reach back at most three bytes; keep the existing stateful reader for short inputs and preserve the existing partial-tail/`check_eof` semantics rather than changing the already-published tail staging path.

Where it lives

perfloop/simdjson · src/icelake.cpp

Evidence

icelake sparse UTF-8, 1 MiB, stride 100, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 53778 54028 +180.4 −1122 to +1561 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 19501121159 19416914374 −65354129 −500499369 to +389747134 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 150, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 39060 39046 +42.04 −883.6 to +930.1 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 26856036886 26858303028 −29905449 −552411700 to +490757209 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 200, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 31734 31761 −103.2 −1028 to +961.3 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 33056571299 33040825140 +118631079 −919509015 to +938840413 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 300, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 24740 24722 +61.36 −1004 to +1148 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 42393183474 42448472339 −90462975 −1863281523 to +1645609761 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 500, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 21161 21138 +71.32 −961.6 to +990.8 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 49878241446 49775049300 −199565428 −2068212895 to +2391617828 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 520, O2 · 115 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 20151 20857 +3.6% (+716.9) +446.5 to +916.4 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 52450655662 50442594799 −3.8% (−1992248025) −2539802380 to −1339576281 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 64 KiB, stride 100, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 3363 3370 +19.07 −87.89 to +63.83 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 19495786077 19451636785 −110327357 −319491613 to +455848432 loss ≤ 0.05 × |baseline median| PASSED

icelake UTF-8 clusters, 1 MiB, stride 1500, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 18259 18157 −128.4 −943.5 to +656.3 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 57729428918 58074656629 +451008996 −2195851151 to +2503727501 loss ≤ 0.05 × |baseline median| PASSED

icelake UTF-8 clusters, 1 MiB, stride 4096, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 15503 11302 −27.3% (−4238) −4573 to −3216 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 69138717981 98007377656 +42.3% (+29278902775) +20728625900 to +31609188333 loss ≤ 0.05 × |baseline median| PASSED

icelake French-like UTF-8, 1 MiB, O2 · 34 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 104877 105887 +1075 −2116 to +4518 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 10038704972 9948101091 −118632242 −419447109 to +173787471 loss ≤ 0.05 × |baseline median| PASSED

icelake Russian-like UTF-8, 1 MiB, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 78297 61128 −22.1% (−17307) −19824 to −15319 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 13396554411 17155129793 +28.5% (+3814254759) +3343004856 to +4172302583 loss ≤ 0.05 × |baseline median| PASSED

icelake alternating UTF-8 batches, 1 MiB, O2 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 48431 41861 −13.1% (−6341) −8774 to −4316 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 21656328937 25185663687 +15.8% (+3423256821) +2293449798 to +4660362229 loss ≤ 0.05 × |baseline median| PASSED

icelake ASCII UTF-8, 64 KiB, O3 · 19 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 1060 816.2 −22.6% (−239.6) −276.9 to −229.6 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 61824010573 80317027060 +29.5% (+18238324911) +17030971354 to +20373285866 loss ≤ 0.05 × |baseline median| PASSED

icelake ASCII UTF-8, 1 MiB, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 15858 12042 −23.5% (−3731) −4209 to −3125 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 67633803530 90276774703 +32.9% (+22273855914) +15869832133 to +23996779271 loss ≤ 0.05 × |baseline median| PASSED

icelake multilingual UTF-8, 1 MiB, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 78215 62695 −19.9% (−15567) −17296 to −14757 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 13408382316 16733866293 +24.9% (+3343130679) +3121934190 to +3552046122 loss ≤ 0.05 × |baseline median| PASSED

icelake sparse UTF-8, 1 MiB, stride 300, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 24745 24632 −113.1 −2139 to +582 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 42402411550 42591994717 +124361787 −973393747 to +3267259247 loss ≤ 0.05 × |baseline median| PASSED

icelake malformed boundary UTF-8, 4 KiB, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 52.48 52.76 +0.2832 −1.194 to +1.871 loss ≤ 0.05 × |baseline median| PASSED
input_bytes_per_second 78222802163 77791129103 −587703198 −2904188055 to +1393146478 loss ≤ 0.05 × |baseline median| PASSED

icelake malformed boundary UTF-8, 64 KiB, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 964.4 727.4 −24.7% (−238.2) −251 to −210.6 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 70059238064 94335823366 +35% (+24509744191) +22181537292 to +25776370057 loss ≤ 0.05 × |baseline median| PASSED

icelake malformed boundary UTF-8, 1 MiB, O3 · 20 sample pairs

metric baseline candidate paired median change confidence range required result
elapsed_ns 15840 12028 −23.9% (−3783) −4542 to −2640 gain > 0; gain > 0.05 × |baseline median|; arm medians separated PASSED
input_bytes_per_second 68017197670 90124875710 +32.8% (+22311890484) +12955141634 to +26137014457 loss ≤ 0.05 × |baseline median| PASSED

Checks: 2 of 2 passed. Verification: no defect found.

Timeline