perf: introduce AST to avoid reparse #205
Merged
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.
Introduce AST and refactor all parsers into an unified tokenizer (the name is not
parser
for historical reasons), replaceinstanceof
s withTokenKind
and type guards. Improved performance by 8%~117%, following are details for difference cases:output
literal x 108,864 ops/sec ±0.76% (80 runs sampled) +66.79%
truncate x 118,342 ops/sec ±0.61% (81 runs sampled) +73.99%
date x 108,593 ops/sec ±1.17% (80 runs sampled) +74.70%
escape x 153,442 ops/sec ±1.00% (77 runs sampled) +85.92%
default x 127,896 ops/sec ±1.62% (73 runs sampled) +65.83%
tag
if x 110,173 ops/sec ±1.44% (81 runs sampled) +41.53%
unless x 98,669 ops/sec ±0.95% (75 runs sampled) +45.01%
for x 51,197 ops/sec ±0.94% (84 runs sampled) +117.51%
switch x 60,840 ops/sec ±0.64% (81 runs sampled) +75.66%
assign x 140,554 ops/sec ±1.16% (77 runs sampled) +76.76%
capture x 106,354 ops/sec ±1.19% (77 runs sampled) +36.83%
increment x 165,727 ops/sec ±1.15% (77 runs sampled) +46.86%
decrement x 179,814 ops/sec ±1.04% (75 runs sampled) +52.63%
tablerow x 57,498 ops/sec ±0.73% (77 runs sampled) +86.36%
demo
demo x 20,497 ops/sec ±4.61% (75 runs sampled) +100.30%
layout
cache=false x 4,670 ops/sec ±2.72% (76 runs sampled) +8.45%
cache=true x 11,940 ops/sec ±0.77% (80 runs sampled) +26.68%
memory
3.000 kB lorem-html before GC x 1.091 kB/tpl (1024 instances sampled) -80.93%
3.000 kB lorem-html after GC x -0.352 kB/tpl (1024 instances sampled)
2.115 kB todolist before GC x 16.636 kB/tpl (1024 instances sampled) +4.85%
2.115 kB todolist after GC x 14.225 kB/tpl (1024 instances sampled)