Optimize String code unit search with V128 - #3816
Conversation
Coverage Report for CI Build 5169Coverage decreased (-0.1%) to 91.111%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
697817d to
91b2850
Compare
Review sign-off (Claude)Reviewed the diff, rebased onto latest RebaseThe interesting part of this rebase was the overlap with #3818, which merged first and already brought Correctness
Observation (non-blocking)With #3818 merged, Verification (rebased tip, moon 0.1.20260731 nightly)
🤖 Generated with Claude Code |
Independent benchmark verification (Claude)Reproduced the PR's benchmark claims on a separate machine (native ARM64,
The headline claims reproduce: ~5× on full 256-code-unit scans (the offset-view case came in slightly better than claimed), and the immediate-match case is flat at 1.00× — no regression when the needle is at position 0. The small-n rows differ from the claimed ratios by fractions of a nanosecond, within run-to-run noise at that scale, and agree in direction: modest gains, no regressions. 🤖 Generated with Claude Code |
Summary
String::contains_code_unitandStringView::contains_code_unitwith eight-wide scans on native and wasm targetsWhy
Code-unit searches previously inspected one UTF-16 code unit at a time. The new intrinsic allows native and wasm backends to scan eight code units per iteration while preserving the existing behavior and public API.
Impact
Long missing or late-match searches are substantially faster on SIMD-enabled targets. String views continue to honor their exact backing-string bounds, and non-native/non-wasm targets keep the scalar path. Generated package interfaces are unchanged.
Benchmark
Isolated native ARM64 release runs comparing the scalar baseline with this implementation (lower is better):
String, absent, n=4String, absent, n=8String, present at 0, n=8String, absent, n=256StringView, absent, n=256The SIMD path improves full scans substantially while keeping the immediate-match case effectively unchanged.
Validation
moon fmtmoon info(no.mbtichanges)moon check --target all -p builtinmoon test --target all -p builtinmoon test: 6,716 passed