fix(emit): clone the wire copy per module, never the whole envelope (#180) - #188
Merged
Conversation
…180) One structuredClone of the envelope hits Bun's serialization ceiling on a large repository (TypeError at 13k files on 1.3.0; a hard abort with no exception at ~2 GiB on 1.3.14, measured). The internal-field strip only touches modules, so each module is cloned on its own and the rest of the root is shared by reference.
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.
Closes #180.
finalizeAnalysiscloned the entire envelope with onestructuredCloneonly to strip INTERNAL fields without touching the live treeresult.internalhands back. That single object is what crosses Bun's serialization ceiling on a large repository. The strip only ever touches modules, so the clone is now per module — the largest single module is megabytes, never gigabytes — and everything else on the root (call_graph,param_in/param_out, artifacts, config edges, the entrypoint report) is shared by reference.Measured on Bun 1.3.14 (this machine):
structuredCloneof a 700 MiB and a 1100 MiB object succeeds; at ~2.2 GiB the process aborts with rc 133 and no exception. The 1.3.0 wheel reported aTypeErroron whole-vscode instead — a different manifestation of the same ceiling. I could not re-run whole-vscode here (no checkout); the reporter's table (593 MBsrc/succeeds, 13,226 files fails) is consistent with the whole-envelope clone being the trigger, and per-module cloning removes it by construction.Tests:
test/finalize-clone.test.ts—structuredCloneis called exactly once per module and never on the envelope/root (fails onmain: 1 call), every wire module is detached from and stripped relative to its internal twin (twin intact,content_hashkept per #118), and a later mutation of the internal tree does not leak into the finalized wire.