Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ Hints:

Bend works best on the back-end, on Linux or macOS.

Bun's native code emitter samples heap use every 64 definitions and collects
at 2 GiB, then after each 2 GiB of growth. Live compiler state is not capped.

# Examples

### Syntax == Python + dependent types
Expand Down
6 changes: 6 additions & 0 deletions bend2/comp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,7 @@ export function compile_book(book: Bend.Book): string {
...names.map((c) => Bend.book_fam(FL.book, c))]);
const facts = () => FL.own.size + FL.hot.size + FL.stat.size;
let was: number;
let pressure = 2 ** 31;
do {
was = facts();
[FL.lend, FL.spun, FL.clos, FL.tabs, FL.lits, FL.consts, FL.brws]
Expand All @@ -2798,6 +2799,11 @@ export function compile_book(book: Bend.Book): string {
for (const [k, tld] of [...done_defs().reverse(),
...done_defs(def_foreign)]) {
memo_gc();
// Collect on heap growth, not the host's total RAM budget.
if (process.memoryUsage().heapUsed > pressure) {
globalThis.Bun?.gc(true);
pressure = process.memoryUsage().heapUsed + 2 ** 31;
}
const [dl, vals] = emit_open(scope_new(), k);
FL.segs.push(dl.seg);
if (def_foreign(tld)) {
Expand Down