Calling a SIMD search engine once per row makes short-string matching slower than an inline loop
Symptom#
After a string like kernel moved onto a shared pattern engine (Highway literal search), simple patterns got slower per row: MPI_% 3.0 to 10.8 ns, %p%e%d% 7.8 to 11.8 ns, _write 1.7 to 8.1 ns, while regex patterns got 15 to 80 times faster.
Cause#
The old kernel checked simple patterns inline in its own loop. The new one called into the engine for every row, and for short strings the Highway dispatch costs more than the search.
Fix#
Use a plain scalar search for short strings, and make the simple matchers (prefix, suffix, equality, literal) and the compiled-pattern layout inline code in an internal header, so the kernel loop runs them without a call. Keep the regex engine (PCRE2) out of line.
Evidence#
dftracer-utils, duql_eval_bench against commit f758477f: after the fix MPI_% took 3.1 ns against 2.8 ns before, and %p%e%d% matched the old time. _write stayed about 0.5 ns slower (2.2 against 1.6 ns): about 0.2 ns for the UTF-8 step the new _ rule needs, the rest code layout.
Also found by searching
- duql_eval_bench: like 'MPI_%' went from 3.0 ns to 10.8 ns per row after moving to Highway literal search
- simple LIKE prefix patterns got 3x slower per row after switching to a shared SIMD pattern engine, regex got faster
- how do I keep short-string prefix and suffix matching fast when using a SIMD search library?
- google highway dynamic dispatch overhead per call dominates on short strings, inline scalar matcher instead
- like kernel got slower per row after switching to Highway SIMD literal search, MPI_% 3 ns to 10 ns
- benchmark regression: short string matching slower after moving to a vectorized pattern engine
- why is calling a SIMD substring search per row slower than a simple loop for short strings?
- highway dispatch overhead per call on small strings, prefix suffix equality matcher should be inline