Skip to content

build: stream page writes instead of holding every page in memory #56

Closed

Description

@lukeed

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:

  1. 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.
  2. 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

  1. 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.
  2. Make bongo build stream its page writes. Leave dev as it is.
  3. 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

  1. added
    enhancement
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions