Skip to content

perf(ext/node): convert _stream_* polyfills to lazy-loaded JS - #33988

Merged
bartlomieju merged 1 commit into
mainfrom
perf/lazy-load-stream-internals
May 12, 2026
Merged

bartlomieju merged 1 commit into
mainfrom
perf/lazy-load-stream-internals

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Continues the work from #33967 by moving the five node:_stream_*
polyfills (_stream_duplex, _stream_passthrough, _stream_readable,
_stream_transform, _stream_writable) off the eager-evaluated ESM
path. The underlying
internal/streams/{duplex,passthrough,readable,transform,writable}.js
files are rewritten as IIFEs registered under lazy_loaded_js, with
thin _esm.js wrappers in lazy_loaded_esm re-exporting the named
members.

internal/streams/duplexify.js and internal/streams/from.js are also
moved from esm to lazy_loaded_esm, since nothing in the eager graph
references them after the conversion.

Continues the work from #33967 by moving the five `node:_stream_*`
polyfills (`_stream_duplex`, `_stream_passthrough`, `_stream_readable`,
`_stream_transform`, `_stream_writable`) off the eager-evaluated ESM
path. The underlying `internal/streams/{duplex,passthrough,readable,
transform,writable}.js` files are rewritten as IIFEs registered under
`lazy_loaded_js`, with thin `_esm.js` wrappers in `lazy_loaded_esm`
re-exporting the named members.

`internal/streams/duplexify.js` and `internal/streams/from.js` are also
moved from `esm` to `lazy_loaded_esm` since nothing in the eager graph
references them after the conversion.
@bartlomieju
bartlomieju merged commit a38610c into main May 12, 2026
268 of 270 checks passed
@bartlomieju
bartlomieju deleted the perf/lazy-load-stream-internals branch May 12, 2026 13:07
bartlomieju added a commit that referenced this pull request May 12, 2026
…#33997)

Follow-up to #33988. Moves the `node:_tls_common`, `node:_tls_wrap`, and
`node:net` polyfills off the eager-evaluated ESM path by rewriting their
sources as IIFEs registered under `lazy_loaded_js`, with thin
`_esm.ts`/`_esm.js` wrappers in `lazy_loaded_esm` re-exporting the named
members.

`net.ts` reads `Duplex` from `node:stream` and `ADDRCONFIG`/`lookup`
from `node:dns` at module top level, so `net_esm.ts` adds side-effect
imports of both — without them, the lazy createLazyLoader calls hit a
not-yet-loaded module when `_http_agent.js` pulls `node:net` very early
during 01_require.js instantiation. For the same reason
`internal/tty.js`'s top-level `ObjectSetPrototypeOf(WriteStream...,
lazyNet().Socket.prototype)` is deferred into an
`ensureWriteStreamPrototype()` helper called from the `WriteStream`
constructor, so it never reaches into `net_esm.ts`'s `Socket` export
while that wrapper is still mid-evaluation. `_readline.mjs` and
`node:readline = readline.ts` also relocate from `esm` to
`lazy_loaded_esm` without IIFE conversion, since `repl.ts` still
statically imports `_readline.mjs`. The `node:repl` conversion is left
for a follow-up: `repl.ts` reads `Module`, `process`, `Console`, etc.
at module top level, and the only IIFE-compatible workaround is a
Proxy-based deferred accessor that I'd rather not introduce.
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…nd#33988)

Continues the work from denoland#33967 by moving the five `node:_stream_*`
polyfills (`_stream_duplex`, `_stream_passthrough`, `_stream_readable`,
`_stream_transform`, `_stream_writable`) off the eager-evaluated ESM
path. The underlying
`internal/streams/{duplex,passthrough,readable,transform,writable}.js`
files are rewritten as IIFEs registered under `lazy_loaded_js`, with
thin `_esm.js` wrappers in `lazy_loaded_esm` re-exporting the named
members.

`internal/streams/duplexify.js` and `internal/streams/from.js` are also
moved from `esm` to `lazy_loaded_esm`, since nothing in the eager graph
references them after the conversion.
littledivy pushed a commit to crowlKats/deno that referenced this pull request Jun 10, 2026
…denoland#33997)

Follow-up to denoland#33988. Moves the `node:_tls_common`, `node:_tls_wrap`, and
`node:net` polyfills off the eager-evaluated ESM path by rewriting their
sources as IIFEs registered under `lazy_loaded_js`, with thin
`_esm.ts`/`_esm.js` wrappers in `lazy_loaded_esm` re-exporting the named
members.

`net.ts` reads `Duplex` from `node:stream` and `ADDRCONFIG`/`lookup`
from `node:dns` at module top level, so `net_esm.ts` adds side-effect
imports of both — without them, the lazy createLazyLoader calls hit a
not-yet-loaded module when `_http_agent.js` pulls `node:net` very early
during 01_require.js instantiation. For the same reason
`internal/tty.js`'s top-level `ObjectSetPrototypeOf(WriteStream...,
lazyNet().Socket.prototype)` is deferred into an
`ensureWriteStreamPrototype()` helper called from the `WriteStream`
constructor, so it never reaches into `net_esm.ts`'s `Socket` export
while that wrapper is still mid-evaluation. `_readline.mjs` and
`node:readline = readline.ts` also relocate from `esm` to
`lazy_loaded_esm` without IIFE conversion, since `repl.ts` still
statically imports `_readline.mjs`. The `node:repl` conversion is left
for a follow-up: `repl.ts` reads `Module`, `process`, `Console`, etc.
at module top level, and the only IIFE-compatible workaround is a
Proxy-based deferred accessor that I'd rather not introduce.
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.

1 participant