Benchmarking an engine through your own wrapper can reverse the verdict
PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
Vectorscan looked 1.4x-45x slower than PCRE2-JIT.
Cause#
The wrapper ran a full UTF-8 validation pass and hs_alloc_scratch on every call (that call validates the database each time, 200-450 ns per call).
Fix#
Time the raw engines first: raw hs_scan against raw PCRE2-JIT on the same strings showed Vectorscan 2x-12x faster from 256 B up. Call hs_scan first and only alloc scratch when it returns HS_INVALID. Keep scratch space thread-local and allocated once, and put the cheap reject check before any validation pass.
Evidence#
Measured in dftracer-utils (duql); PCRE2-JIT stayed faster on alternation and character-class patterns at every length.
Also found by searching
- vectorscan looked 1.4x-45x slower than PCRE2-JIT
- benchmark through a wrapper gives the opposite result of the raw engines
- hs_alloc_scratch validates the database on every call, 200-450 ns
- how do I fairly compare two regex engines