Repository navigation
perf(ext/node): convert _stream_* polyfills to lazy-loaded JS - #33988
Merged
Merged
Conversation
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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 ESMpath. The underlying
internal/streams/{duplex,passthrough,readable,transform,writable}.jsfiles are rewritten as IIFEs registered under
lazy_loaded_js, withthin
_esm.jswrappers inlazy_loaded_esmre-exporting the namedmembers.
internal/streams/duplexify.jsandinternal/streams/from.jsare alsomoved from
esmtolazy_loaded_esm, since nothing in the eager graphreferences them after the conversion.