Repository navigation
Emission allocates 40% less on large files: per-file literal steps, per-def probes, no memo closures (#1262) - #1617
Merged
Merged
Conversation
… and restarts probes per def
…a call allocates no closure
Lorenzobattistela
approved these changes
Oct 16, 2026
nicolas-abril
added a commit
to nicolas-abril/bend
that referenced
this pull request
Oct 19, 2026
comp.ts keeps this branch's structure, with upstream's changes ported in: bendlang#1615's frame-slot write-back in bind_pop; bendlang#1617's named memo functions (open_of, spine_of, uses_of), per-file literal steps keyed by string, and lay_at memoized per type key (FL.ty_opens, keyed by ty_key); bendlang#1625's F32.read regex; bendlang#1628's string_contains. bendlang#1617's per-def PROBES reset is left out: here probes and the term caches live as long as the file and units emit again across sweeps, so a reset would reuse probe indices still held in FL.opens and FL.uses. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
nicolas-abril
added a commit
to nicolas-abril/bend
that referenced
this pull request
Oct 19, 2026
bendlang#1617 split them into named functions to save a closure per call; on this branch that changes neither emit time nor peak memory, measured on boss_3d, hvm5_mini and walkers_test and on a quarter of the corpus. Output is byte-identical. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Merged
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.
Part of #1262. This lowers how much
compile_bookallocates while it emits a large file. It doesn't fix the root cause: emission still re-runs the whole file about 8 times while facts settle (#1386).Measured on Chromi's
examples/eco/main.bend. On main that file fails withduplicate declaration of Text, so I renamed itsText{toAText{for the measurement. The emitted C is byte-identical to main's.bun main.tswall time, 3 runsRSS depends on when Bun's GC happens to run, and it is too noisy to call a win or a loss.
Changes (
comp.tsonly, +58/−47):term_forcememoizes literal steps per file, keyed byk + v. Before, they were memoized per def and keyed by the term object, so the same literal got stepped again in every def and in every pass (29.2 → 23.1 GiB).compile_bookresetsPROBESbefore each def. Before, it only reset infile_new, so it grew from about 131k to 1M entries across the passes. Now it stays at about 430 (23.1 → 22.4 GiB). This is the part to review closely. It's only safe if no probe from an earlier def is still alive in a cache that outlivesmemo_gc(). The newstepsandopensmaps hold only probe-free results.telespredates this PR and isn't cleared per def.lay_atmemoizes its open-type check (ty_holds(A, Var|App)) per file, keyed byterm_key(term_lower(A))(22.4 → 18.8 GiB).term_uses,term_openandterm_spinepass named functions tomemoand no longer allocate a closure on every call.term_usesfolds with a loop (18.8 → 17.4 GiB).What's left, from the heap profile: each of the ~8 fixpoint passes allocates about 2.2 GiB (#1386). U32 literal matching (
mat_rows/mat_lits) takes about 1.5 GiB, andterm_higherabout 2.5 GiB.Checks (macOS M-series, at 539c7e6): ping 59/59, test 1639/1639, perf 124/124, repo 53/54. The one repo failure is the token cap:
bend2/comp.tsis 64187 > 64000 ttok. main is already over it at 64092 (repo-gate is red on main), and this PR adds 95. Not run: Linux, CUDA, Metal, hub corpus.safe.tsisn't touched.