Skip to content

lib: lazy-load builtins not used during startup#63926

Open
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:perf-bootstrap
Open

lib: lazy-load builtins not used during startup#63926
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:perf-bootstrap

Conversation

@watilde

@watilde watilde commented Jun 15, 2026

Copy link
Copy Markdown
Member

Defer builtins that aren't needed on a bare startup to first use:

  • blob – fs.openAsBlob() and URL.createObjectURL() now load
    internal/blob / the blob binding lazily (also drops the
    internal/encoding tree it pulled in).
  • url_pattern – URLPattern is now a lazy export, exposed via
    exposeLazyInterfaces instead of forcing the binding at bootstrap.
  • typescript – internal/modules/typescript loads only when a .ts
    source is actually stripped.

Impact

node -e "", 100 interleaved before/after runs via performance.nodeTiming:

Metric Before After Ξ”
builtins at startup 113 106 βˆ’7
bootstrapComplete (median) 11.70 ms 11.45 ms βˆ’2.1%

Modest, since the compiled code already lives in the snapshot.

Test

test-bootstrap-modules.js updated to drop the 7 no-longer-loaded entries.
url / urlpattern / module / blob / typescript / es-module suites and
make lint-js pass locally.

Defer the url_pattern and blob bindings and the typescript builtin
until they are first used, instead of requiring them unconditionally
during bootstrap. Loading internal/blob lazily also drops the
internal/encoding tree it pulled in.

This removes 7 builtins from the startup module list (113 -> 106) and
reduces bootstrapComplete by ~2% (median 11.70ms -> 11.45ms), measured
with performance.nodeTiming over 100 interleaved runs.

- fs.openAsBlob() and URL.createObjectURL() load internal/blob and the
  blob binding on demand
- URLPattern is exposed via exposeLazyInterfaces and no longer forces
  the url_pattern binding at bootstrap
- TypeScript type stripping loads internal/modules/typescript only when
  a .ts source is actually processed

Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/startup
  • @nodejs/url
  • @nodejs/web-standards

@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 Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants