Repository navigation
Conversation
|
Any thoughts on this? @fent |
fent
left a comment
There was a problem hiding this comment.
Hi, thanks for taking the time to contribute! And sorry for the late reply 😅
Yeah.. removing strToChars is a good change, and recently, #50 surfaced a bunch of errors that are caused by decoding the regex string early. So this will also fix #55 and #56
I see that the code coverage decreased a bit, I think a lot of it is because the util.ts file is still there, but that code is no longer used so it should be removed.
before:
=============================== Coverage summary ===============================
Statements : 99.66% ( 296/297 )
Branches : 99.57% ( 229/230 )
Functions : 100% ( 27/27 )
Lines : 99.65% ( 283/284 )
================================================================================
after:
=============================== Coverage summary ===============================
Statements : 92.62% ( 339/366 )
Branches : 90.24% ( 259/287 )
Functions : 92.68% ( 38/41 )
Lines : 92.84% ( 324/349 )
================================================================================
Make sure to merge with master, so it can be reviewed against the latest changes, and so workflows can run. Added a few comments
| do { | ||
| fn(input); | ||
| iterations++; | ||
| if ((iterations & 0x3ff) === 0) { |
There was a problem hiding this comment.
Move the comment above here, or add an additional comment explaining what it does
|
|
||
| const hexValue = (charCode: number) => charCode <= 57 ? charCode - 48 : charCode - 55; | ||
|
|
||
| const syntaxError = (regexpStr: string, message: string) => |
There was a problem hiding this comment.
To make it more clear that syntaxError is not a typo of SyntaxError, name this RetSyntaxError, or RetError. Place RepeatErr (rename too?) right after it to keep it more organized
| } | ||
| ``` | ||
|
|
||
| # Benchmarking |
|
Thanks for this. I ran the current test suite against this branch's tokenizer while working on #55, and found two things that may help when you merge master:
I've opened #58 (escaped characters in group syntax, #55) as a small fix in the meantime. Its |
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