Repository navigation
Description
Hey, I was directed to do this by i2cjak. I'm just an LLM, sorry.
We're using Bend 2.0.36 for Backplane and hitting memory limits at application scale; upstream is now 2.0.39. Our tree has about 33,000 definitions and 3,100 laws. Main.boot reaches about 25,000 definitions across 335 modules.
Observed hub emits have used roughly 13–18 GiB peak RSS, and a web emit about 8 GiB. Our proof workload is budgeted around 18 GiB; mobile's earlier footprint was reported around 7 GB. These figures come from different runs, not a matched benchmark. Our large compiler runs use a 1,048,576 KiB stack limit and BUN_JSC_maxPerThreadStackUsage=4000000000 where needed.
Experiments so far:
- Module-prefix checking hit a 6 GB cap after 152 modules, with no output; some boundaries spent about 4.8 seconds checking, compacting and collecting.
- Paged bodies brought a mobile check to about 2.7 GiB RSS, but one measured version took 183 seconds versus 88 seconds for the preceding prototype. Its bridge was reused, not re-emitted. Hub and web have not qualified under the 3.7 GB compiler cap: web completed checking but OOM-killed during analysis; a hub attempt timed out, and another instrumented attempt OOM-killed after checking.
- Smaller proof partitions still hit the limit: 104 of 531 attempted shards OOM-killed. Only six failures were down to one law; these local capped experiments did not have the full admission and controller receipt.
- Independent template instances can receive the same generated name for different bodies when units start with empty template state. A linker must preserve or reconcile that state and reject collisions.
- Our source restructuring has isolated some small laws; the largest measured individual law closure remains about 5,500 definitions. This is distinct from the 25,000-definition
Main.bootclosure, which remains whole.
Ideas that might help include separate compilation with interface files, streaming emit, incremental caching, checking against interfaces where sound, and less GC churn and stack depth. Dependent conversion can need bodies, and law-fill order and template state matter, so interface-only checking needs a carefully defined contract.
We published experimental, unqualified snapshots and design notes in a public fork: paged bodies, batch-128, streaming emit, module mode, and separate-compilation notes. Thanks for maintaining Bend!
Activity
i2cjak commentedon Nov 4, 2026
Stock-scaling follow-up: I did not establish a reproducible quadratic definition-count bug in unpatched Bend with these synthetic inputs.
Measured unchanged 2.0.36 (
ae1101ca) and upstream main reporting 2.0.39 (ea66e004), using their source APIs under Bun 1.3.10. Independent and fan-in programs had 2,000 / 4,000 / 8,000 / 16,000 / 32,000 definitions, three fresh-process repetitions per case on the same normal 4-vCPU Boat VM. Every compiler run had a kernel-enforced 3.7 GB memory cap (readback 3,699,998,720 bytes), swap disabled and a 120 s timeout.Fitted wall-time exponent
t ~ N^p:Public reproducer and pinned compiler hashes, all per-phase wall/peak-RSS tables and fit intervals, and individual numeric records. The harness calls unchanged load/check/JS-library-emission functions; endpoint outputs matched the unchanged CLI byte for byte. Emit includes backend analysis and exports all host-callable definitions, rather than just the application's main.
We also measured private, complete-module, dependency-closed hub prefixes of 2,031 / 3,981 / 8,152 / 16,148 / 32,482 source definitions. On 2.0.36, all three 16k attempts and all three 32k attempts were OOM-killed at the cap, confirmed by systemd. On 2.0.39, both larger prefixes instead fail to parse because our
Toolname collides with Base; those are compatibility failures, not timing samples. Some completed real-prefix slopes exceed one (current 2.0.36 parse: 1.20; 2.0.39 emit: 1.43), but their code composition changes, larger points are censored, and the latter interval is 0.73–1.86. That does not isolate an asymptotic compiler bug. No application source is published.The earlier hub 13–18 GB / proof ~18 GB observations remain unmatched historical figures, not peaks reproduced by these capped runs. Sound separate compilation/interfaces, streaming emit and incremental caching remain useful questions. Our paged-prototype costs are separate and were not used as stock evidence. Thanks!
nicolas-abril commentedon Nov 6, 2026
This doesn't address the root cause in the compiler, but it seems that most of the memory in the case of backplane comes from doing matches with string literal patterns. If you change it to "if String.equal(...)" instead it gets both much faster and takes much less memory.
nicolas-abril commentedon Nov 6, 2026
Thanks for the detailed report and the experiment branches. I measured the public BackplaneWorks/Backplane tree directly: the hub entry
src/server/main.bend(386 files, 9.2 MB, 31.3k defs), on 2.0.36 and on current main (e75ccac0). Setup: macOS, Node 26 / Bun 1.3.14, single runs.The main cause: string-literal patterns
Most of the memory comes from string literals in
casepatterns (#1266). The flattener expands a literal into its constructors down to the bits of each character (about 33 tests per character), and copies the match's other rows, bodies included, at every failure point. The expanded tree is what every later phase walks.case.Hub.answer.kis 9 lines and stores 1.43M nodes. Others in the top ten:View.kn.acts(1.04M),Run.after.go(766k),Alerts.asks(714k),Node.rows.button(658k),KN.install.acts(612k),Tio.main.k(541k),Browser.unpaged(512k).Replacing the 750 literals in
casepatterns with_(a stand-in for aString.eqrewrite; check still passes):_(Node)_(Bun, yourBUN_JSC_forceRAMSize=4GiB)Workaround: rewrite those defs to match on
String.eq(x, "lit")in a helper def, as you already do in places such asHub.answer.cx.t. OnHub.answer.k's shape this takes the stored body from 734,010 nodes to 134. Rewriting the 133 defs above 10k nodes should capture nearly all of the gain. #2075 compilesString.eqto===on JS, so this form is also fast at runtime (1.92 s → 0.01 s for 2M comparisons of 17-character strings).On upgrading: main currently emits string-pattern-heavy code worse than 2.0.36. The OOM above bisects to 3ed8746 (#1817). Without string patterns, main is better than 2.0.36 (2.6 vs 4.4 GB). So rewrite the patterns before upgrading, or wait for a fix. The
Toolname collision you hit is a new Base name; see #1913.The proper fix keeps a literal pattern as one node, so no rewrite is needed. It needs a checker rule, and is tracked in #1266, where I posted the details.
Other contributors
bend.ts/comp.tsfrom a harness under Node, not the CLI.Your patches
js-literal-compact: superseded by Emission allocates 40% less on large files: per-file literal steps, per-def probes, no memo closures (#1262) #1617, which shares the literal expansion per file. It made no difference on main.emit-search-shortcutandjs-stream-sink: no measurable effect on main either.I'm leaving this open for the literal-split fix (#1266) and the #1817 regression.