repl: lazy-load acorn and defer vm context creation#63879
Open
watilde wants to merge 1 commit into
Open
Conversation
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>
anonrig
approved these changes
Jun 13, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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):
In isolation, require('repl') drops from 4.64ms to 2.84ms (-39%) and interactive
node -istartup improves by ~13%.