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: stream page writes instead of holding every page in memory #56
bongo build holds the final HTML of every page in memory, and writes nothing until every page is ready. Dev needs this, because a failed rebuild must leave the last good build serving. bongo build does not need it: it writes into an emptied public/, so a failed build has nothing to keep. On a very large site, the memory that the build holds grows with the size of all pages.
Today
In packages/bongo/src/build.ts, walk 2 collects each rendered page in pages. After the bundler flush, bongo substitutes the asset placeholders in each page, runs $hooks.transform, and writes every file at once ("every file is ready before any is written").
The constraint
A page can be final only after the bundler flush. Its HTML holds placeholders for hashed asset names, and the flush needs the registrations of all pages before it can run. So bongo build cannot write a page as soon as its layouts render, unless it does one of these:
Write each page with its placeholders as soon as it renders. Then, after the flush, read each file again, substitute the placeholders, transform it, and write it, a few files at a time.
Render in two passes: a first pass that only collects the asset registrations, then the flush, then a second pass that renders and writes each page.
Keep a Set of the pages that the build has emitted, so that no page renders or writes twice.
Plan
Benchmark first. Add a benchmark that generates a large site (for example 10,000 Markdown pages, with layouts, partials, a stylesheet, and a script). Record the time and the peak memory (process.memoryUsage().rss, or /usr/bin/time -l) of bongo build on the current code.
Make bongo build stream its page writes. Leave dev as it is.
Run the same benchmark again, and put both results in the PR.
Acceptance
The peak memory of bongo build on the large site goes down, and its time does not get worse.
bongo build writes the same files, byte for byte, as before.
Dev keeps its rule: a failed rebuild leaves the last good build serving.
Activity