perf(ext/node): convert net, _tls_common, _tls_wrap to lazy-loaded JS#33997
Merged
Conversation
Continues the work from #33988 by moving the `node:_tls_common`, `node:_tls_wrap`, and `node:net` polyfills off the eager-evaluated ESM path. `_tls_common.ts`, `_tls_wrap.js`, and `net.ts` are rewritten as IIFEs registered under `lazy_loaded_js`, with thin `_esm.ts`/`_esm.js` wrappers in `lazy_loaded_esm` re-exporting the named members. `net_esm.ts` adds side-effect imports of `node:stream` and `node:dns` so that `net.ts`'s top-level `createLazyLoader(...)()` calls hit already-evaluated modules rather than failing during 01_require.js instantiation. `internal/tty.js`'s top-level `ObjectSetPrototypeOf(WriteStream..., lazyNet().Socket.prototype)` calls move into an `ensureWriteStreamPrototype()` helper invoked from the WriteStream constructor; this avoids reaching into `net_esm.ts`'s `export const Socket` binding while the wrapper module is still mid-evaluation. `_readline.mjs` and `node:readline = readline.ts` also relocate from `esm` to `lazy_loaded_esm` (no IIFE conversion since `repl.ts` still statically imports `_readline.mjs`).
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.
Follow-up to #33988. Moves the
node:_tls_common,node:_tls_wrap, andnode:netpolyfills off the eager-evaluated ESM path by rewriting theirsources as IIFEs registered under
lazy_loaded_js, with thin_esm.ts/_esm.jswrappers inlazy_loaded_esmre-exporting the namedmembers.
net.tsreadsDuplexfromnode:streamandADDRCONFIG/lookupfrom
node:dnsat module top level, sonet_esm.tsadds side-effectimports of both — without them, the lazy createLazyLoader calls hit a
not-yet-loaded module when
_http_agent.jspullsnode:netvery earlyduring 01_require.js instantiation. For the same reason
internal/tty.js's top-levelObjectSetPrototypeOf(WriteStream..., lazyNet().Socket.prototype)is deferred into anensureWriteStreamPrototype()helper called from theWriteStreamconstructor, so it never reaches into
net_esm.ts'sSocketexportwhile that wrapper is still mid-evaluation.
_readline.mjsandnode:readline = readline.tsalso relocate fromesmtolazy_loaded_esmwithout IIFE conversion, sincerepl.tsstillstatically imports
_readline.mjs. Thenode:replconversion is leftfor a follow-up:
repl.tsreadsModule,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.