This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
25x speed improvement in tokenizing jquery.min: maxCachedIndex should not dicrease due to a cache miss #40
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.
@kevinsawicki @zcbenz I would be most thankful if you take a look at this PR, as both VSCode and Atom would benefit from it :).
TL;DR
maxCachedIndex
is a safeguard to protect against unitialized access toresults
(to ensure the regex at a certain index has been tried at least once), therefore it should only grow in theSearch
method, since it gets correctly reset to-1
in theClear
method.Long version
I have noticed the following wrong behavior through logging and running the first-mate benchmark. Suppose the following example:
result->LocationAt(0) >= byteOffset
)maxCachedIndex
gets incorrectly set to0
Turns out this makes a huge difference in practice:
Before my proposed change:
After my proposed change:
About running the benchmarks:
IsSame
was always false for me in this node version). I ran both benchmarks with this change in, without this I gave up after 20min of waiting:tokenizeLines
has changedI would be very thankful if you cherry pick this to master and also publish a new v4 on npm with this change, if you agree with my reasoning.
Thank you