Commit 745a43e
committed
repl: lazy-load acorn and defer vm context creation
Merely loading the repl builtin used to eagerly require acorn and
acorn-walk (~250KB of JS) and create an entire V8 context via
vm.runInNewContext() just to enumerate global property names, even
though both are only needed once REPL input is actually parsed or
tab-completion is used.
Require acorn and acorn-walk at their function-level use sites
instead, and wrap the global builtins set in getLazy(). The cost
moves to the first preview/completion/recoverable-error check,
where the one-time ~1ms is imperceptible.
Benchmark results (Linux x64, misc/startup-core.js, 20 runs):
require-builtins.js: +3.12% ops/s (t=3.57, p<0.01)
import-builtins.mjs: +2.20% ops/s (t=3.00, p<0.01)
In isolation, require('repl') drops from 4.64ms to 2.84ms (-39%)
and interactive `node -i` startup improves by ~13%.
Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
PR-URL: #63879
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>1 parent 1434a07 commit 745a43e
3 files changed
Lines changed: 22 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 64 | | |
72 | 65 | | |
73 | 66 | | |
| |||
87 | 80 | | |
88 | 81 | | |
89 | 82 | | |
| 83 | + | |
| 84 | + | |
90 | 85 | | |
91 | 86 | | |
92 | 87 | | |
| |||
374 | 369 | | |
375 | 370 | | |
376 | 371 | | |
377 | | - | |
378 | | - | |
| 372 | + | |
| 373 | + | |
379 | 374 | | |
380 | 375 | | |
381 | 376 | | |
| |||
387 | 382 | | |
388 | 383 | | |
389 | 384 | | |
| 385 | + | |
390 | 386 | | |
391 | 387 | | |
392 | 388 | | |
| |||
551 | 547 | | |
552 | 548 | | |
553 | 549 | | |
| 550 | + | |
554 | 551 | | |
555 | 552 | | |
556 | 553 | | |
| |||
625 | 622 | | |
626 | 623 | | |
627 | 624 | | |
| 625 | + | |
628 | 626 | | |
629 | 627 | | |
630 | 628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 23 | | |
| 24 | + | |
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
| |||
80 | 78 | | |
81 | 79 | | |
82 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
756 | 757 | | |
757 | 758 | | |
758 | 759 | | |
| 760 | + | |
| 761 | + | |
759 | 762 | | |
760 | 763 | | |
761 | 764 | | |
| |||
815 | 818 | | |
816 | 819 | | |
817 | 820 | | |
818 | | - | |
819 | | - | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
820 | 824 | | |
821 | 825 | | |
822 | 826 | | |
| |||
848 | 852 | | |
849 | 853 | | |
850 | 854 | | |
851 | | - | |
| 855 | + | |
852 | 856 | | |
853 | 857 | | |
854 | 858 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
| |||
153 | 149 | | |
154 | 150 | | |
155 | 151 | | |
156 | | - | |
| 152 | + | |
157 | 153 | | |
158 | 154 | | |
159 | 155 | | |
| |||
249 | 245 | | |
250 | 246 | | |
251 | 247 | | |
| 248 | + | |
| 249 | + | |
252 | 250 | | |
253 | 251 | | |
254 | 252 | | |
| |||
1139 | 1137 | | |
1140 | 1138 | | |
1141 | 1139 | | |
1142 | | - | |
| 1140 | + | |
1143 | 1141 | | |
1144 | 1142 | | |
1145 | 1143 | | |
| |||
0 commit comments