replace string slices with startsWith comparison #9
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.
This commit replaces string slice operations in the lexer with
startsWith
operations, using an offset position to start the search from. This avoids intermediate string slices so should be easier on the allocator and garbage collector.I am seeing a performance improvement of -14% on average with these changes, as measured on the following system:
CPU: AMD Ryzen 3700X @ 3.6GHz (turbo'ing disabled for more stable results)
Mem: 64GB
OS: macOS 10.15.2 (Hackintosh)
Node.js: 14.13.0
Samples: 1000 (increased from default 25)
The WASM results are not affected, obviously:
Raw output:
master (4d56d33)
PR
I am curious to see results on other hardware, as the measurements in the readme show that JS is roughly 47% slower than WASM, but for me it's only 29% on master; this is reduced to just 11% with these changes.