Skip to content

lib: include ESM loader in the built-in snapshot#61769

Closed
joyeecheung wants to merge 7 commits intonodejs:mainfrom
joyeecheung:esm-in-snapshot
Closed

lib: include ESM loader in the built-in snapshot#61769
joyeecheung wants to merge 7 commits intonodejs:mainfrom
joyeecheung:esm-in-snapshot

Conversation

@joyeecheung
Copy link
Member

@joyeecheung joyeecheung commented Feb 11, 2026

Benchmark number from an ARM64 Linux machine: empty/minimal CJS startup is now slightly slower in worker but other metrics get a slight boost (because they all incur ESM loader initialization). In reality ESM loading is likely to happen at some point in the lifetime of an application especially with the growing adoption of ESM and require(esm), so real-world applications that are more than just an empty script should get a bit of speed up from being able to just deserialize the ESM loader instead of initializing it from scrach.

                                                                                         confidence improvement accuracy (*)   (**)  (***)
misc/startup-core.js n=30 mode='process' script='benchmark/fixtures/empty.mjs'                  ***      6.06 %       ±0.60% ±0.80% ±1.04%
misc/startup-core.js n=30 mode='process' script='benchmark/fixtures/import-builtins.mjs'        ***      2.40 %       ±0.30% ±0.40% ±0.52%
misc/startup-core.js n=30 mode='process' script='benchmark/fixtures/require-builtins.js'        ***      0.57 %       ±0.32% ±0.42% ±0.55%
misc/startup-core.js n=30 mode='process' script='test/fixtures/semicolon.js'                            -0.22 %       ±0.56% ±0.75% ±0.97%
misc/startup-core.js n=30 mode='worker' script='benchmark/fixtures/empty.mjs'                   ***      1.89 %       ±0.26% ±0.34% ±0.44%
misc/startup-core.js n=30 mode='worker' script='benchmark/fixtures/import-builtins.mjs'         ***      0.74 %       ±0.28% ±0.38% ±0.49%
misc/startup-core.js n=30 mode='worker' script='benchmark/fixtures/require-builtins.js'         ***     -2.20 %       ±0.26% ±0.34% ±0.44%
misc/startup-core.js n=30 mode='worker' script='test/fixtures/semicolon.js'                     ***     -1.95 %       ±0.30% ±0.40% ±0.52%

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/performance
  • @nodejs/startup

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 11, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.77%. Comparing base (37ff1ea) to head (cdf427a).
⚠️ Report is 28 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #61769      +/-   ##
==========================================
+ Coverage   89.74%   89.77%   +0.02%     
==========================================
  Files         675      674       -1     
  Lines      204735   204759      +24     
  Branches    39348    39355       +7     
==========================================
+ Hits       183737   183815      +78     
+ Misses      13269    13233      -36     
+ Partials     7729     7711      -18     
Files with missing lines Coverage Δ
lib/internal/bootstrap/switches/is_main_thread.js 95.92% <100.00%> (+0.01%) ⬆️
lib/internal/modules/esm/get_format.js 94.83% <100.00%> (+1.68%) ⬆️
lib/internal/modules/esm/loader.js 98.76% <100.00%> (+1.79%) ⬆️
lib/internal/modules/esm/resolve.js 98.94% <100.00%> (+2.74%) ⬆️
lib/internal/modules/esm/translators.js 97.64% <100.00%> (+5.26%) ⬆️
lib/internal/process/pre_execution.js 95.98% <100.00%> (+0.01%) ⬆️
lib/internal/repl/completion.js 95.13% <100.00%> (ø)

... and 59 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@watilde watilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question for my understanding: I noticed defaultResolve and defaultLoadSync are still lazy-loaded with ??= while translators was moved to pre-loading. Is this because:

  • These are only used when there are no custom loader hooks (less common path)?
  • Their dependencies are heavier and would hurt startup more?
  • Or is this something that could be optimized similarly in the future?

Just curious about the design rationale

@joyeecheung
Copy link
Member Author

I noticed defaultResolve and defaultLoadSync are still lazy-loaded with ??= while translators was moved to pre-loading.

Did you mean in esm/loader.js? I believe I've removed them. If not could you leave a pointer to the line where it still remains? Happy to update them in this PR.

@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Feb 12, 2026
@watilde
Copy link
Member

watilde commented Feb 12, 2026

My code base in my local was very old, nvm. Thank you!

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 12, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 12, 2026
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Feb 13, 2026
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/61769
✔  Done loading data for nodejs/node/pull/61769
----------------------------------- PR info ------------------------------------
Title      lib: include ESM loader in the built-in snapshot (#61769)
Author     Joyee Cheung <[email protected]> (@joyeecheung)
Branch     joyeecheung:esm-in-snapshot -> nodejs:main
Labels     lib / src, needs-ci, commit-queue-rebase
Commits    3
 - lib: remove top-level getOptionValue() calls in lib/internal/modules
 - lib: reduce cycles in esm loader and load it in snapshot
 - benchmark: add startup benchmark for ESM entrypoint
Committers 1
 - Joyee Cheung <[email protected]>
PR-URL: https://github.com/nodejs/node/pull/61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 11 Feb 2026 04:52:49 GMT
   ✔  Approvals: 3
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/61769#pullrequestreview-3782914586
   ✔  - Daijiro Wachi (@watilde): https://github.com/nodejs/node/pull/61769#pullrequestreview-3784562017
   ✔  - Geoffrey Booth (@GeoffreyBooth): https://github.com/nodejs/node/pull/61769#pullrequestreview-3787902819
   ✘  Last GitHub CI failed
   ℹ  Last Full PR CI on 2026-02-12T15:02:50Z: https://ci.nodejs.org/job/node-test-pull-request/71322/
- Querying data for job/node-test-pull-request/71322/
✔  Build data downloaded
- Querying failures of job/node-test-commit/85439/
✔  Data downloaded
   ✘  44 failure(s) on the last Jenkins CI run
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/21975249143

@joyeecheung
Copy link
Member Author

Looks like this got broken by #61665 which added filtering of internal frames but the regex couldn't understand async frames. Updated the regex to handle async frames. cc @legendecas

@joyeecheung joyeecheung added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. request-ci Add this label to start a Jenkins CI on a PR. labels Feb 13, 2026
@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member Author

Looks like the new regex didn't work with test runner outputs somehow. Updated. Can you take a look again? @legendecas Thanks!

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2026
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member Author

Fixed the test-bootstrap-modules list for workers. Can you take a look again? Thanks!

@legendecas @mcollina @GeoffreyBooth @watilde @JakobJingleheimer @RafaelGSS

@legendecas legendecas added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 19, 2026
@joyeecheung joyeecheung added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2026
@nodejs-github-bot
Copy link
Collaborator

Landed in 9cd6630...53ac826

nodejs-github-bot pushed a commit that referenced this pull request Feb 19, 2026
PR-URL: #61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Feb 19, 2026
PR-URL: #61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Feb 19, 2026
PR-URL: #61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Feb 19, 2026
PR-URL: #61769
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Daijiro Wachi <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Jacob Smith <[email protected]>
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. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

Comments