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
{{ message }}
Repository navigation
build: the last build stays in memory after build() returns #59
After build() returns, the data of that build stays in memory until the next build replaces it. On the 10,000-page site of bun run bench (#56), the live JS heap after a full GC is 500 MB when build() returns. Before the build, it is 3 MB.
The chain
A heap snapshot after the build shows this chain, from the module to the pages:
templates.collect() assigns the blocks from makeBlocks(argv, config) onto the module-level blocks object. Each block closure keeps config, which is the template context of run().
The context has $assets. Its render method is a closure that run() makes, in assets().
A closure keeps the scope of run(), and that scope holds every local that a closure in run() uses.
So these stay live:
local of run()
size
ready, the final HTML of each file
180 MB
scanned, with the body of each page
64 MB
pages, the HTML of each page with placeholders
45 MB
The next collect() replaces the blocks, and only then can the GC free the last build. The size does not grow from one build to the next, so this is a hold, not a leak.
Effect
bongo dev calls the same build(), so between rebuilds it holds the last build twice: once in the memory sink, and once through this chain.
bongo build exits after the build, so this does not change its peak.
Repro
bun run bench site --runs 1
In the stage table, read "heap at start" on the exit row: it is the live heap after build() returns.
Acceptance
After build() returns, the live heap goes back near its level before the build.
bongo build writes the same files, byte for byte, as before.
The compiler closure in templates.collect() (packages/bongo/src/utils/templates.ts, the compiler function for each partial) also keeps config, the template context, because it spreads config on each call. Partials and blocks[key] both hold these compilers. So a change to makeBlocks() alone does not free the last build.
No code deletes keys from blocks. bongo dev clears Partials and Layouts on a rebuild, but a partial that you delete or rename stays in blocks. So across renames in dev, the held set can grow; "a hold, not a leak" is true only while the partial names stay the same.
Direction: give the template state an explicit life of one build. Keep the registries and blocks in a context for each build, and pass it to rendering. Move the assets() factory out of run(), and pass it only the values it needs. Compiled templates can stay cached if they do not keep the build context.
Measure: run several builds in one process, also a failed build and a rename of a partial, and read the heap after a full GC after each build. The bench runs each build in a new process, so it cannot show this fix by itself.
Activity
lukeed commentedon Oct 15, 2026
More detail from a review of this issue:
templates.collect()(packages/bongo/src/utils/templates.ts, thecompilerfunction for each partial) also keepsconfig, the template context, because it spreadsconfigon each call.Partialsandblocks[key]both hold these compilers. So a change tomakeBlocks()alone does not free the last build.blocks.bongo devclearsPartialsandLayoutson a rebuild, but a partial that you delete or rename stays inblocks. So across renames in dev, the held set can grow; "a hold, not a leak" is true only while the partial names stay the same.Direction: give the template state an explicit life of one build. Keep the registries and blocks in a context for each build, and pass it to rendering. Move the
assets()factory out ofrun(), and pass it only the values it needs. Compiled templates can stay cached if they do not keep the build context.Measure: run several builds in one process, also a failed build and a rename of a partial, and read the heap after a full GC after each build. The bench runs each build in a new process, so it cannot show this fix by itself.
fix: free the last build
fix: free the last build