Keep N=1 Unicode confirmation inside the AVX-512 scan

perfloop/casei · LATE FILTERING

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

Verdict

VERIFIED · settled 2026-08-22 · pull request opened as tsenart/casei#10

What happened: The paired measurements met the required improvement.

Hypothesis

I checked `casei.searchPlan.findUnicodePairAnchor` at `plan.go:2200-2227` and its indexed callees. It calls `pairPairSkipBytes` at line 2203, then calls `matchesSingleAt` at lines 2208 and 2221 to confirm candidate starts. `pairPairSkipBytes` selects the AVX-512 `pairPairSkip64` kernel when its existing feature and length guards apply. The accepted Case-insensitive compiled-plan search hot path reaches this exact body through `casei.IndexFold`, `casei.searchPlan.find`, and the Unicode pair-anchor branch.

The submitter reports roughly 2,134 survivors for a 35-byte Russian literal on one audited corpus; I did not reproduce that measurement here. Source does show that pair-pair filtering emits a candidate to Go before decoded full confirmation, and a rejected candidate can restart scanning through the byte skipper. If false survivors dominate, that is late filtering across the Go/assembly boundary: a broad intermediate crosses the boundary before the narrower exact-match check rejects it. A fused scan-and-confirm kernel could reject an anchor and continue in the same bulk loop, but its end-to-end benefit remains a hypothesis.

Confirm by counting anchor survivors, false confirmations, and scanner reentries on the stated N=1 Unicode shapes. Differentially fuzz simple folding, invalid-byte opacity, offsets, and leftmost behavior across feature modes; inspect object disassembly for spills and per-candidate table or pattern reloads; then compare randomized measurements on Ice Lake and Sapphire Rapids against the existing path while checking the multi-pattern and BenchmarkBar rows.

Change to test: For eligible N=1 literals with width-stable simple folds, fuse the pair-pair scan and full bounded confirmation into an AVX-512F/BW/VBMI transition that continues scanning after a mismatch and returns only an exact match. Retain the decoded `matchesSingleAt` executor for width-changing or opaque folds, long literals, and unsupported hosts.

Where it lives

perfloop/casei · matcher.go

Evidence

AVX-512 VBMI N=1 Unicode 1.5 MiB false-survivor Matcher.Find field row · 10 sample pairs

metric baseline candidate paired median change confidence range required result
ns/op 450578 75130 −83.3% (−375453) −381673 to −373478 < −22529 PASSED
x_vs_best 4.547 0.7328 −84.1% (−3.823) −3.905 to −3.757 < −0.2273 PASSED
candidate_active 1 1 0 0 to 0 ≥ 0 PASSED
candidate_vector_bits 512 512 0 0 to 0 ≥ 0 PASSED
competitors 4 4 0 0 to 0 ≥ 0 PASSED
entrants 5 5 0 0 to 0 ≥ 0 PASSED
go_ac_active 0 0 0 0 to 0 ≤ 0 PASSED
go_ac_vector_bits 0 0 0 0 to 0 ≤ 0 PASSED
pcre2_active 1 1 0 0 to 0 ≥ 0 PASSED
pcre2_vector_bits 128 128 0 0 to 0 ≥ 0 PASSED
regexp_active 1 1 0 0 to 0 ≥ 0 PASSED
regexp_vector_bits 0 0 0 0 to 0 ≤ 0 PASSED
rure_active 0 0 0 0 to 0 ≤ 0 PASSED
rure_vector_bits 0 0 0 0 to 0 ≤ 0 PASSED
rustac_active 0 0 0 0 to 0 ≤ 0 PASSED
rustac_vector_bits 0 0 0 0 to 0 ≤ 0 PASSED
stringzilla_active 1 1 0 0 to 0 ≥ 0 PASSED
stringzilla_vector_bits 512 512 0 0 to 0 ≥ 0 PASSED
vectorscan_active 1 1 0 0 to 0 ≥ 0 PASSED
vectorscan_vbmi 1 1 0 0 to 0 ≥ 0 PASSED
vectorscan_vector_bits 512 512 0 0 to 0 ≥ 0 PASSED
veloz_active 0 0 0 0 to 0 ≤ 0 PASSED
veloz_vector_bits 0 0 0 0 to 0 ≤ 0 PASSED

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

Timeline