This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
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.
PR checklist
bugfix, orenhancementWhat changes did you make?
SkippableTokenAwareRuleWalker
is totally overkill to just find the start and end position of identifiers, regex literals and template expressions.I added the utility function
getSkippableTokens
to do exactly the same without the walker overhead. This function also takes advantage of proper tail calls if implemented in the vm.Also the code for skipping tokens while scanning was copied to 5 different classes. I added a new function
scanAllTokensWithSkip
(name is for discussion) to address 4 of them.Performance
I turns out that the overall performance gain for the 4 walkers is around 50%.
I profiled linting of
tslint
sources. Total time was 14s. Before this change each ofEnableDisableRuleWalker
,CommentFormatRule
,JsdocFormatRule
andNoTrailingWhitespaceRule
accounted for around 260ms (~1.85% of total).With this change each execution time reduces to under 120ms (~0.85% of total).
Is there anything you'd like reviewers to focus on?
whitespaceRule
actually needs the walker to do its thing, so I left it untouched. Usingutils.getSkippableTokens
would walk the AST a second time. The slowdown is almost not measurable, but there is no real benefit either. Also the skipping logic here is different, as it needs to add failures before skipping.