Add ASCII fast path to gototab to avoid bsearch#264
Open
yhirose wants to merge 1 commit intoonetrueawk:stagingfrom
Open
Add ASCII fast path to gototab to avoid bsearch#264yhirose wants to merge 1 commit intoonetrueawk:stagingfrom
yhirose wants to merge 1 commit intoonetrueawk:stagingfrom
Conversation
Each state's gototab gains a direct-indexed array for ASCII code points (0..GOTO_DIRECT-1), letting get_gototab and set_gototab return in a single load on the common path. Non-ASCII still goes through the existing sorted (codepoint, state) entries via bsearch, so behavior is unchanged. On the testdir/Compare.tt suite this cuts total time by ~14%; pure regex matches like /.$/ run about 2.3x faster.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a per-state direct-indexed array for ASCII code points to
gototab,so
get_gototabandset_gototabreturn in a single load on the commonpath. Non-ASCII still falls through to the existing sorted (codepoint,
state) entries via
bsearch, so behavior is unchanged. Same dense-tabletechnique gnulib's
dfa.cuses, narrowed to ASCII.Performance on
testdir/Compare.tt(Apple M1, default-O2 -g):/.$/)Same ratio under
-O3 -DNDEBUG -flto -mcpu=apple-m1.Per-state struct grows by
GOTO_DIRECT * sizeof(int) = 512 bytes,about 5% of the existing per-state
entriescalloc.