perf: improve tokenizer scanning and add benchmark suite#51
Open
smith558 wants to merge 3 commits intofent:masterfrom
Open
perf: improve tokenizer scanning and add benchmark suite#51smith558 wants to merge 3 commits intofent:masterfrom
smith558 wants to merge 3 commits intofent:masterfrom
Conversation
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.
Summary
The tokeniser now parses regex source directly instead of doing an upfront escaped-string rewrite and slice-based parsing for character classes and
{m,n}repetitions.What Changed
strToChars()pass from tokenization{m,n}parsertokenizerreconstructroundtripREADMEWhy
The main goal is to reduce per-parse allocations and avoid unnecessary rescans of the input string, especially on patterns with character classes and custom repetitions.
The benchmark suite is included so future tokeniser changes can be measured with representative workloads instead of one-off local scripts.
Benchmark
I compared the current branch against
HEAD~2locally using the same benchmark case set.Tokeniser results:
2.753x2.975xSelected tokeniser cases:
4.922x4.027x3.447x3.147x3.144xRoundtrip results:
1.826xreconstructalso benchmarked faster in this harness, but tokenizer is the primary target of the change.Testing
npm run buildnpm testnpm run bench -- --min-ms 200Notes
The benchmark suite is intentionally dependency-free and runs against the built dist output:
npm run benchnpm run bench -- --suite tokenizer --min-ms 750