Skip to content

tail alternatives: match stateless tail alts with a plain loop - #74

Open
gobwas wants to merge 1 commit into
masterfrom
feature/tail-alts
Open

gobwas wants to merge 1 commit into
masterfrom
feature/tail-alts

Conversation

@gobwas

@gobwas gobwas commented Sep 8, 2026

Copy link
Copy Markdown
Owner

A tail alternatives whose branches are all stateless can never be resumed: each branch either matches the whole remainder or fails deterministically. Fold such alts into tailAltMatcher -- the branches are tried in order with no checkpoints and no matchState, so e.g. {abc*def,abc?def,abc[zte]def} now matches without touching the state pool at all.

Alternative-heavy benchmarks improve 65-75% (24ns -> 8ns on the shaped ones, 61ns -> 21ns on the four-branch row); patterns with stateful branches ({abc,d}) or non-tail alts ({a,b}c) are unchanged.

A tail alternatives whose branches are all stateless can never be
resumed: each branch either matches the whole remainder or fails
deterministically. Fold such alts into tailAltMatcher -- the branches
are tried in order with no checkpoints and no matchState, so e.g.
{abc*def,abc?def,abc[zte]def} now matches without touching the state
pool at all.

Alternative-heavy benchmarks improve 65-75% (24ns -> 8ns on the shaped
ones, 61ns -> 21ns on the four-branch row); patterns with stateful
branches ({a*b*c,d}) or non-tail alts ({a,b}c) are unchanged.
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