You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the JSON cache key from #1166 copies shared child layouts into a tree. That can turn a small type into a huge string before the compiler even checks the cache.
The regression below just returns Ready{42}, but compiling it exceeds 800 MiB because another alternative in its result type contains nested sums.
Scope
Use layout identity and the normalized type as show_main's cache key, through the existing memo helper. One net compiler line and a 16-line regression. The layout distinction from #1166 stays intact.
Tradeoffs
Separate layout objects with equal structure may get separate descriptors. This avoids expanding the graph or adding a structural interner.
Blast radius
Display descriptors for pure-main results in JS and native builds. IO mains bypass this cache.
Verification
On macOS arm64, Bun 1.3.11 and clang 23.1.2. The reproduction command is:
bun bend2/main.ts tests/reg/show_shared_layout.bend -o /tmp/show_shared_layout.js
Compiling the new regression to JS on eb8f58b crossed an 800 MiB sampled-RSS limit and the watchdog stopped it. With this fix, the same command completed in 0.10 s at 113 MiB sampled RSS.
The regression passes checking, interpreter, emitted JS and native execution, printing Ready{42}.
Ten existing tests and one mixed-type control pass, including all three fix(compiler): key display descriptors by layout #1166 regressions. Their emitted C and JS are byte-identical to main. The unprintable-main diagnostic also matches.
bun gates/repo.ts: 49/49. git diff --check passes. Compiler size is 63,778/64,000 tokens, 13 more than main.
Hey @nicolas-abril , I was reviewing this PR and dug into the tradeoff since you moved #1166 to the JSON key on purpose. Two data points:
Across all 143 pure-main files in tests/demos/benches, the JSON key never merged two nodes that the identity map would keep apart. Layouts are already interned per type by lay_of, so the only case where it fires is an Array element's open layout matching a flat value, and it saves one descriptor row.
The cost: JSON.stringify expands shared layouts as a tree, so nested sums double the key per level. This PR's regression builds a 1.5 GB key. Memory goes 79 MiB → 225 MiB from n=12 to 18 and gets OOM-killed at 24
But I see you reverted a very similar change on the #1166 mentioned, i'm trying to get the rationale behind it.
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
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.
Why
the JSON cache key from #1166 copies shared child layouts into a tree. That can turn a small type into a huge string before the compiler even checks the cache.
The regression below just returns
Ready{42}, but compiling it exceeds 800 MiB because another alternative in its result type contains nested sums.Scope
Use layout identity and the normalized type as
show_main's cache key, through the existingmemohelper. One net compiler line and a 16-line regression. The layout distinction from #1166 stays intact.Tradeoffs
Separate layout objects with equal structure may get separate descriptors. This avoids expanding the graph or adding a structural interner.
Blast radius
Display descriptors for pure-main results in JS and native builds. IO mains bypass this cache.
Verification
On macOS arm64, Bun 1.3.11 and clang 23.1.2. The reproduction command is:
eb8f58bcrossed an 800 MiB sampled-RSS limit and the watchdog stopped it. With this fix, the same command completed in 0.10 s at 113 MiB sampled RSS.Ready{42}.bun gates/repo.ts: 49/49.git diff --checkpasses. Compiler size is 63,778/64,000 tokens, 13 more than main.Cluster, GPU and benchmark gates were not run.