Repository navigation
Description
What you did
Used bend 2.0.40 for the first time. Immediately crashed memory.
Reproduction:
git clone https://github.com/dmbarbour/glam-in-bend
cd glam-in-bend && git checkout 9922172
cd spike && bend kernel.bend -o kernel.cWhat happened
Peak memory measured in a cgroup of its own (memory.peak).
- bend 2.0.39: peak 1.9 GB, 18 s.
- bend 2.0.40: killed at a 6 GB cap after 20 s, and at a 7 GB cap. With
BUN_JSC_forceRAMSize=1000000000it finishes at 7.6 GB, 38 s.
The emitted C is about the same: 3.57 MB against 3.91 MB, and 2,332
spin_ functions against 2,327. --check-only takes 0.9 GB. The JS
target is unaffected: on a smaller program, 1.2 GB against 1.1 GB.
Programs that call into a smaller part of the same code grow faster than
their output: for 0.4 to 1.1 MB of C, 1.9 to 3.0 GB under 2.0.40 against
1.0 to 1.2 GB under 2.0.39.
The likely cause is in comp.ts. In 2.0.39, FL.memo held the
opens, uses, folds and spines caches, and memo_gc() cleared
them for each definition the emit loop visited. In 2.0.40 those caches
live on FL, along with the new ground and ty_opens, and only
FL.folds is cleared, in unit_emit. The caches are Maps keyed by
term objects (all but ty_opens), so they keep every unit's terms
alive. I emitted the C for a program of 1.1 MB of output, then forced a
full GC (Bun.gc(true)):
| 2.0.39 | 2.0.40 | |
|---|---|---|
| heap used | 459 MB | 1,754 MB |
ground entries |
(cleared) | 2.28M |
opens entries |
(cleared) | 1.02M |
spines entries |
(cleared) | 266K |
uses entries |
(cleared) | 251K |
To test it, I patched the bundle inside the release binary to clear the
caches alongside folds:
function unit_emit(u) {
FL.folds.clear();
[FL.opens, FL.uses, FL.spines, FL.ground, FL.ty_opens].forEach((m) => m.clear());I ran the patched bundle under the binary's own Bun (BUN_BE_BUN=1).
The C it emits is byte-identical to the release's. Peak memory:
- the kernel: 2.8 to 3.0 GB in three of four runs (the fourth 6.2 GB),
30 s; - the 1.1 MB program: 3.0 GB down to 1.8 GB.
A WeakMap, as FL.keys already is, might do as well.
What remains above 2.0.39 (1.9 GB, 18 s) I haven't traced. The units
that fill the caches most are a template-heavy rewrite
(krules:rewrite_id~0 to ~3): 165K opens and 324K ground entries
in one unit.
One more difference between the releases: 2.0.40's binary embeds Bun
1.3.14, while 2.0.39's embedded 1.4.0.
(Issue co-authored by Opus.)
bend version
bend 2.0.(39,40) - transition
uname -sm
Linux x86_64 (Intel i7-6700, 16 GB)
clang --version (the first line)
Debian clang version 19.1.7 (3+b1)
Activity
[-]Peak Memory Explooooosion[/-][+]Peak Memory Explooooosion (bend 2.0.40 requires too much memory)[/+]aivv73 commentedon Nov 7, 2026
Note
🤖 gpt-6.1-sol responding on behalf of aivv73
The bundled Bun version also changes whether C emission completes for our project-sized input. This may be useful evidence for the runtime change noted above, although I have not established a connection to the memo-cache retention described in this issue.
I ran the same unmodified Bend 2.0.40 source (
624dd9f4607cd29b0871a9b96d413bfb11e92f52) against the same input using two embedded Bun runtimes:Error: the machine stack overflowed (a deep recursion, or a literal too large to expand).Both runs executed
bend2/main.tsdirectly throughBUN_BE_BUN=1, so the comparison does not depend on differences between the two bundled compiler programs:The input is Entangle's window verification driver, including its imports. It uses our Bend 2.0.40 Vulkan compatibility patch. This is not yet a reduced, self-contained reproducer.
Environment: Linux x86_64, Clang 23.1.4. The failing command emits C and does not invoke Clang. I have not collected memory measurements for this comparison or identified the underlying cause.
fix(comp): a bit-trie level runs arm_self only on a row it keeps (#2076)
fix(comp): a bit-trie level runs arm_self only on a row it keeps (#2076…
nicolas-abril commentedon Nov 10, 2026
Fixed on
mainby #2107 and #2108. The fix ships in the next release.The kernel and the other
spike/programs. glam-in-bend at9922172, macOS arm64, Bun 1.3.14 for every version, one run at a time:mainkernel.bendtest_levels.bendrunmode.bendThe other ten runnable
spike/programs are also at or below 2.0.39 onmain. These are peak RSS figures, not cgroupmemory.peak, so they compare the releases with each other, not with the numbers above.Bun is not the cause of the blowup. The same compiler source behaves the same under both release Buns (the one 2.0.39 embeds, 1.4.0, and the one 2.0.40 embeds, 1.3.14). 2.0.40's source peaks at about 8.4 GB on the kernel under either Bun, and
main's at 2.7–3.9 GB. 2.0.40 got Bun 1.3.14 because the release embeds the Bun of the machine that builds it, and nothing pins a version.The Entangle driver (the comment above): Entangle at
cde97524, withbend-vulkan@a144f7dplus the retained patch, builttools/verify-mesh-window.bend -o x.c. The 2.0.40 release reproduces "the machine stack overflowed" after 14.7 s at 6.0 GB. The real error isRangeError: Out of memoryfromMap.set:Mapat 25,165,824 entries, whatever the free memory, and Bun 1.4.0 caps it at 50,331,648.FL.groundcache, which is never cleared, grew past the 1.3.14 limit on this driver. Bun 1.4.x has twice the room, which is why it passed there.RangeErroras a stack overflow (A RangeError that is not a stack overflow is reported as one #2120), so a larger stack could not help.On
mainthe caches are dropped between units, andFL.groundpeaks at 1.3M entries. The driver compiles in about 3.2 s at 3.1–3.5 GB under both Bun 1.3.14 and 1.4.0, with identical C, so pinning Bun 1.4.4 won't be needed once the next release is out.fix(cli): only a stack overflow prints the stack overflow message (#2122