Skip to content

repl: lazy-load acorn and defer vm context creation#63879

Closed
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:perf-improve
Closed

repl: lazy-load acorn and defer vm context creation#63879
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:perf-improve

Conversation

@watilde

@watilde watilde commented Jun 12, 2026

Copy link
Copy Markdown
Member

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%.

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>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Jun 12, 2026
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jun 13, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@watilde watilde added the review wanted PRs that need reviews. label Jun 17, 2026
watilde added a commit that referenced this pull request Jun 23, 2026
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>
@watilde

watilde commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

Landed in 745a43e

@watilde watilde closed this Jun 23, 2026
@watilde watilde deleted the perf-improve branch June 23, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. review wanted PRs that need reviews.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants