Skip to content

fix(emit): clone the wire copy per module, never the whole envelope (#180) - #188

Merged
rahlk merged 1 commit into
mainfrom
fix/issue-180-per-module-clone
Sep 7, 2026
Merged

fix(emit): clone the wire copy per module, never the whole envelope (#180)#188
rahlk merged 1 commit into
mainfrom
fix/issue-180-per-module-clone

Conversation

@rahlk

@rahlk rahlk commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Closes #180.

finalizeAnalysis cloned the entire envelope with one structuredClone only to strip INTERNAL fields without touching the live tree result.internal hands 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): structuredClone of 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 a TypeError on 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 MB src/ 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.tsstructuredClone is called exactly once per module and never on the envelope/root (fails on main: 1 call), every wire module is detached from and stripped relative to its internal twin (twin intact, content_hash kept per #118), and a later mutation of the internal tree does not leak into the finalized wire.

…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.
@rahlk
rahlk merged commit 502e2cc into main Sep 7, 2026
1 check passed
@rahlk
rahlk deleted the fix/issue-180-per-module-clone branch September 7, 2026 22:36
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.

structuredClone TypeError in finalizeAnalysis aborts analysis of a large project (vscode, 13,226 files)

1 participant