Skip to content

perf(ext): convert ext/io, ext/os, ext/net JS sources to lazy-loaded scripts#33779

Merged
bartlomieju merged 2 commits into
mainfrom
perf/lazy-loaded-io-os-net
May 2, 2026
Merged

perf(ext): convert ext/io, ext/os, ext/net JS sources to lazy-loaded scripts#33779
bartlomieju merged 2 commits into
mainfrom
perf/lazy-loaded-io-os-net

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Summary

Follow-up to #33760. Converts the ESM JS sources in ext/io, ext/os, and ext/net to IIFE-wrapped lazy-loaded scripts (lazy_loaded_js), eliminating ESM module resolution overhead.

These three extensions have no cross-extension ESM import dependencies (only core.loadExtScript calls to already-converted extensions like ext/web), so no internals bridges are needed.

Converting these also unblocks clean conversion of:

  • ext/fs (depends on ext/io)
  • ext/fetch (depends on ext/net)

Test plan

  • cargo check passes
  • cargo build --bin deno succeeds (snapshot builds)
  • tools/format.js and tools/lint.js --js pass
  • Smoke tested: Deno.hostname(), Deno.stdin, Deno.connect, Deno.connectTls all work
  • CI

@fibibot fibibot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Substance follows the same lazy_loaded_js pattern I approved in #33760 and commented on in #33778, and the body's claim that ext/io/ext/os/ext/net have no cross-extension ESM imports (only core.loadExtScript calls into already-converted extensions) checks out — no internals symbol bridges needed.

Real regression: IIFE wrapper shifts line numbers in stack traces

integration::run::permissions_trace fails on both debug macos-aarch64 and debug linux-aarch64 (so this is deterministic, not a single-platform flake). The expected output asserts:

┃  ├─ Object.hostname (ext:deno_os/30_os.js:43:10)

but actual output after the conversion is:

┃  ├─ Object.hostname (ext:deno_os/30_os.js:45:10)

Two-line shift — the IIFE wrapper ((function () { + setup) adds two lines at the top of 30_os.js, moving Object.hostname from line 43 to line 45. Stack-trace-pinning tests like permissions_trace see this directly.

The permissions_trace regression is the kind of thing #33760 / #33778 didn't trip on because their converted files (16_image_data.js, 00_crypto.js, etc.) weren't on any permissions_trace-style stack. ext/os/30_os.js's Object.hostname is — it's on the canonical "sys access requested" trace path.

Fix: update the expected output in tests/testdata/run/permissions_trace.out (the file the macros line tests/integration/run_tests.rs:430:1 points at) to the new line numbers. Or — cleaner long-term — switch the line numbers to [WILDLINE] so future IIFE/format changes don't cascade. The non-regenerated line-number assertion is going to keep biting on every script-conversion follow-up otherwise.

Other failure

test node_compat (2/3) debug windows-x86_64 fails on parallel/test-dns-resolver-max-timeout.js: timeout1: 505, timeout2: 515 — same Windows DNS-timing flake that's hit ~half the daily PRs. Pre-existing, unrelated.

Substance walk

  • ext/io/lib.rs, ext/os/lib.rs, ext/net/lib.rs all switch the relevant esm = [...] entries to lazy_loaded_js = [...]. Right shape for the now-IIFE files.
  • 23 files, +67/-47 net: most of the diff is the JS-side importcore.loadExtScript migration in consumers, plus the IIFE wrap on the converted files themselves. Smaller than #33778 because there's no equivalent of the giant 00_crypto.js patch.
  • No internals shims — the body's statement that these extensions have no cross-ESM dependencies is verifiable from the diff: every JS-side import either stays import (for files still in ESM form) or migrates to core.loadExtScript (for already-converted extensions like ext/web).

CI

83/106 success at this head, 18 in flight, 3 failures (2 real permissions_trace, 1 unrelated DNS flake). Once the .out fixture is updated for the new line numbers, the substance side is clean and ready for re-CI.

@bartlomieju
bartlomieju merged commit 545e31e into main May 2, 2026
136 checks passed
@bartlomieju
bartlomieju deleted the perf/lazy-loaded-io-os-net branch May 2, 2026 13:49
bartlomieju added a commit that referenced this pull request May 3, 2026
Follow-up to #33760 and #33779. Converts all 8 ESM JS sources in
`ext/fetch` to IIFE-wrapped lazy-loaded scripts (`lazy_loaded_js`).

- `20_headers.js`, `21_formdata.js`, `22_body.js`, `22_http_client.js`,
`23_request.js`, `23_response.js`, `26_fetch.js`, `27_eventsource.js`
- `26_fetch.js` imports from `ext/telemetry` (TypeScript ESM, can't be
converted yet) -- bridged via `internals.__telemetry` /
`internals.__telemetryUtil` set in the telemetry source files
- All other cross-extension deps use `core.loadExtScript()` (ext/web,
ext/webidl, ext/net are already `lazy_loaded_js`)

This also eliminates the `internals.__fetchRequest/Response/Headers`
bridges from #33778 since `ext/cache` can now use `core.loadExtScript()`
for ext/fetch directly.
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…and#33784)

Follow-up to denoland#33760 and denoland#33779. Converts all 8 ESM JS sources in
`ext/fetch` to IIFE-wrapped lazy-loaded scripts (`lazy_loaded_js`).

- `20_headers.js`, `21_formdata.js`, `22_body.js`, `22_http_client.js`,
`23_request.js`, `23_response.js`, `26_fetch.js`, `27_eventsource.js`
- `26_fetch.js` imports from `ext/telemetry` (TypeScript ESM, can't be
converted yet) -- bridged via `internals.__telemetry` /
`internals.__telemetryUtil` set in the telemetry source files
- All other cross-extension deps use `core.loadExtScript()` (ext/web,
ext/webidl, ext/net are already `lazy_loaded_js`)

This also eliminates the `internals.__fetchRequest/Response/Headers`
bridges from denoland#33778 since `ext/cache` can now use `core.loadExtScript()`
for ext/fetch directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants