Skip to content

Perf improvements for splitSepByOneOf - #3266

Merged
harendra-kumar merged 2 commits into
masterfrom
splitSepByOneOf-perf
Oct 21, 2026
Merged

harendra-kumar merged 2 commits into
masterfrom
splitSepByOneOf-perf

Conversation

@harendra-kumar

Copy link
Copy Markdown
Member
  • Keep the pattern groups in strict records instead of lazy tuples. For one-element patterns of 1, 2 or 4 bytes, a hash match is a pattern match, so the byte comparison is skipped.
  • Keep the hash of the longest patterns in the loop state and check it first (14–23% faster on CrossModule).
  • Unbox the first group's fields outside the loop and inline its hash check (3–10% faster).

A packed-word path like the one in splitSepBySeq_ was also tried. It made the single-pattern cases as fast as splitSepBySeq_, but made multi-pattern sets slower and grew the state machine a lot, so it was left out.

Keep each pattern group in a record with strict fields instead of a
lazy tuple, so the per-element loop does not load and test boxed
fields. For one element patterns of size 1, 2 or 4 bytes the hash is
the element itself, so a hash match is a pattern match and the byte
comparison is skipped.
The group of the longest patterns always exists, keep its rolling hash
in the Fill and Loop states instead of the hash array, and check it
before the other groups. With a single pattern length there are no
other groups to walk. Store the pattern hashes in a strict record so
that comparing a hash does not load a tuple and a boxed Word32.

On the CrossModule benchmarks this is 14-23% faster.
@harendra-kumar
harendra-kumar merged commit ddc9afd into master Oct 21, 2026
19 checks passed
@harendra-kumar
harendra-kumar deleted the splitSepByOneOf-perf branch October 21, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant