perf: shrink generated wrapper source#264
Merged
timfish merged 1 commit intoJun 30, 2026
Merged
Conversation
5ea8d97 to
a9ffdcc
Compare
a9ffdcc to
e31b60b
Compare
This reduces iitm's per-module compile cost by emitting the export read / defer / override / set / get wiring once per wrapper rather than per export. On a 396-module / 3258-export graph (synchronous in-thread loader, Node 24.16): wrapper source 2.85 MiB -> 1.25 MiB, compileSourceTextModule 47.1 ms -> 24.8 ms, total wrap+load 192.8 ms -> 144.4 ms.
e31b60b to
f38d8e6
Compare
bengl
reviewed
Jun 30, 2026
| __pending = next | ||
| } | ||
|
|
||
| function __bind (key, write, read, useFallback) { |
Member
There was a problem hiding this comment.
These double-underscores to hide things are going to break at some point.
bengl
approved these changes
Jun 30, 2026
timfish
approved these changes
Jun 30, 2026
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.
Summary
Every wrapped module makes Node compile a generated wrapper, and that compile is the dominant iitm startup cost once the parser is no longer Acorn. Each export inlined ~25 lines of identical read / defer / override / set / get wiring, so a realistic 396-module / 3258-export graph emitted 2.85 MiB of wrapper source for V8 to parse. This moves that wiring into a single
__bindhelper emitted once per wrapper; each export keeps only the liveletbinding and staticexportthe module system requires, plus a one-line__bindcall.Behavior is unchanged: live bindings, deferred resolution for circular imports, the Hook set/get proxy, and the Node 23+
module.exportsfallback all keep their existing semantics.Numbers
396-module / 3258-export graph, synchronous in-thread loader, Node 24.16,
--cpu-prof --cpu-prof-interval=50:compileSourceTextModuleself time: 47.1 ms -> 24.8 msTest plan
npm testtest/register/v22.15-sync-register-hooks*.mjs)module.exportsbuiltin fallback still resolveStacked on #259 (es-module-lexer); the compile win is what remains after the parser swap, so review/merge after that.