Skip to content

feat: incremental builds - #69

Merged
lukeed merged 26 commits into
mainfrom
incremental
Oct 17, 2026
Merged

lukeed merged 26 commits into
mainfrom
incremental

Conversation

@lukeed

@lukeed lukeed commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #66.

bongo build and bongo dev now render only the pages that a change reaches. The other pages keep their files from the last build. bongo build keeps a record of its last good build in node_modules/.cache/bongo/memo.json; bongo dev keeps it in memory. --fresh renders every page.

What renders again

  • A page whose source changed.
  • A page that reads $pages, $tags, or $section (in its source, its layouts, or a partial that it calls), when a page in that list changes its path, title, summary, section, tags, headings, or frontmatter.
  • A page whose $assets.load file changed.
  • In bongo build, a page that links an asset whose sources changed, a module that a script imports included, since the asset's name changes. Dev names scripts and stylesheets by their entry, so an edit to one renders only the pages that inline it or use its CSS module classes.
  • With $hooks.transform, every page when an output file is added, deleted, or changes its frontmatter, since the hook gets the list of output files (@bongo/feed links its feeds from it).
  • A page whose file in public/ changed or is gone.
  • Every page when the config, a local file that it imports, data/, layouts/, partials/, the lockfile, the bongo code, the runtime, or --minify changes. Output files and data modules render on every build.

How

  • Walk 1 stats each source. A source whose size and mtime are as the memo has them keeps its hash, unread; a page that the memo has runs no loader. A file that changed less than 2 s before a build is read again by the next.
  • The memo lists the files of the build in public/, so bongo build does not list the folder. Before a write or a deletion goes through a path, bongo checks it once for a symlink, and deletes one that it finds, never following it. A build without the memo, such as --fresh, lists the folder as before. Emptying public/ deletes the memo.
  • A page that keeps its file replays its asset registrations, renders, and alternates, in bulk. The memo keeps two marks for each asset: a hash of its output's name, exports, and image, and of its content when a page inlines it. After the flush, a kept page renders again when a mark of its own asset changed, as a safety net; in bongo build, the memo's hashes of each asset's sources catch most of these before walk 1, so those pages render once.
  • The memo keeps each page's registry digest, so a kept page joins the registries without JSON and a hash of its record.
  • The memo is one row for each page, written a few rows at a time, and is read only when the same bongo code saved it. It is 7.1 MB for 10,000 pages.
  • The size report takes the sizes that the build already has, and a full GC runs only after 1,000 pages or more render.

Fixes on the way

  • fix: bundle from site root: Rolldown named modules from the process cwd, so the bytes and the hashed name of a script changed with the folder that bongo build -C <dir> ran in. The bench site's hash changes once, to 8a3eb4b55617cb67.
  • fix: default minify to false: the API left minify undefined while the CLI passes false, so each saved a memo under another key.
  • perf: list sizes from build, perf: check tag files once, perf: cache placeholders: the size report stats the build's files at once and no longer walks public/; each file that a tag names is checked once in a build; each asset's placeholder is hashed once.
  • perf: guard transition scan: rewriteTransitionAttrs ran a regex on every opening tag of every page, though most pages have no transition attribute. One search for transition:name or transition:animate now skips such a page. A --fresh build of 10,000 pages went from 2.87 s to 2.54 s in an interleaved A/B.
  • docs: unbroken inline code: inline code no longer breaks after the dashes of a flag such as --minify.

Results

10,000 pages, Apple M1 Max, on a quiet machine. Before is main (#68). Every step writes the same bytes as a --fresh build.

before after
full build 2.82 s · 519 MB 2.40 s · 508 MB
no change 2.82 s 246 ms
body edit 2.82 s 246 ms
title edit / new page 2.82 s 334 / 330 ms
stylesheet / layout edit 2.82 s 2.30 / 2.24 s
dev: first build / layout edit 2.00 / 1.80 s 1.70 / 1.50 s
dev: page edit 0.82 s 0.08–0.09 s
dev: stylesheet edit / new page 1.80 s 0.08 / 0.14 s

Peak RSS of a full build swings from run to run (478–544 MB in this run). Dev holds about 45 MB more JS heap, the memo of 10,000 pages. Whole bench runs swing by about 15 ms for a small change, so each perf: step that cut it was also measured in one interleaved A/B session: a build with no change went from 309 ms to 243 ms over the six steps. bench/results.md has that table and the full tables, and the bench has a new incremental target.

Trade-offs

  • bongo cannot see a change that keeps a source's size and mtime (cp -p, rsync -t), nor what a template, hook, or loader reads by itself (the time, an environment variable, a file that it opens). Use --fresh. $hooks.transform runs only for the pages that render.
  • A file that something else puts in public/ stays until --fresh.

Test plan

  • bun test (833 pass), bunx tsc -p ., bunx tsc -p build, bun run build
  • Each step of the incremental tests, in bongo build and in dev, renders the expected pages and writes the bytes of a fresh build
  • A memo saved by one process applies in the next
  • Stat gate, racy mtime, stray file, symlink in public/, memo deleted on failure, inline marks, memo round trip: each test fails with its feature switched off
  • bun run bench: every incremental step matches --fresh
  • Docs site: the new CLI section on desktop and mobile

lukeed added 26 commits October 15, 2026 12:07
When two script entries of one bundle group had the same name, the
order in which pages registered them chose which got the `-1` suffix.
Content files load several at a time, so that order, and the output
names, could change from one build to the next. Entries now get their
names in path order.
A build now renders only the pages that a change can reach. After each
good build, bongo keeps a memo: `bongo build` saves it in
node_modules/.cache/bongo/memo.json, and dev keeps it in memory.

- A global key covers the bongo code, the runtime, the options, the
  config and the local files it imports, data/, layouts/, partials/,
  and the nearest lockfile. When it changes, every page renders.
- A content file whose hash matches runs no loader; its record goes
  into the registries as it is, and its body loads only if it renders.
- A page renders again when its source, a registry that it read, a
  file that `$assets.load` read, or its output file changed. A page
  reads a registry that its body, a layout of its chain, or a partial
  that it called names, since tempura reaches values only by name.
- A page that keeps its file replays its asset registrations, renders,
  and alternates, before any page renders, so a clash between them
  fails as in a full build.
- After the flush, a kept page renders again if its assets got new
  output names, or if an asset it inlines changed. In dev, scripts and
  stylesheets keep their names when their content changes, so an edit
  to a stylesheet changes no page.
- Output files and data modules run on every build.
- `--fresh` renders every page.

The narrow rebuild of dev (`only`, and the frontmatter signature that
promoted it) is gone: the memo covers it.

Refs #66
Rolldown names modules in its region comments from the process
cwd, so the bytes of a script and its hashed name changed with
the folder that `bongo build -C <dir>` ran in.
The incremental target times a build after each kind of edit and
checks its bytes against a --fresh build. Site, docs, and stage
runs use --fresh, so they still time a full build. Dev steps edit
files for real, since a touch no longer renders anything.
Each page registers the same few assets, so the sha256 of an
entry and its settings is worked out once, not for every page.
A registration is a map lookup, not a loop.
Every page names the same stylesheet and scripts, so a build checks
each file that a tag names once, and forgets at its start, so a file
added after a failed build counts. The path of the client runtime
is found once.
The size report stats the files that the build made, all at once,
and no longer walks public/, one folder for each page.
- The memo keeps each bundle registration once, and stores the
  source files of each asset with their hashes. In bongo build, a
  page that links an asset whose sources changed renders in full
  from walk 1, not again after the flush.
- Walk 2 checks pages at once, and loads the bodies of the next
  pages to render while one renders.
- Pages share one signature for each set of placeholders. Stats
  after the writes run at once.
- Registries hash a short digest of each page.
- The memo saves one line for each item, a few at a time, so its
  save holds no copy of all of it at the build's peak.
The API left it undefined while the CLI passes false, so the two
saved memos under different keys, and each rendered every page
after the other.
$hooks.transform gets the output files of the build, and
@bongo/feed links its feeds from them. With a transform hook, a
page now renders again when an output file is added, deleted, or
changes its frontmatter.
Inline code is one inline block, so a flag such as --minify no
longer breaks after its dashes. A code wider than the line still
wraps inside its box.
What renders again after each kind of change, where the memo
lives, what bongo cannot see, and --fresh. Dev names scripts and
stylesheets by entry, and a transform hook runs only for the pages
that render.
Full builds, docs, a new table of bongo build after each kind of
edit, and dev with the new steps, next to #68 on the same steps.
- A content file whose size and mtime are as the memo has them
  keeps its hash and is not read. A file that changed less than
  2 s before a build is read again by the next, since its mtime
  may not show a second change that soon.
- The memo lists the files of the build in public/, so the next
  bongo build trusts that list and does not list the folder. A
  path that a write or the sweep goes through is checked once for
  a symlink, which is deleted, never followed. A file that
  something else put in public/ stays until --fresh.
- Emptying public/ deletes the memo.
- The memo keeps the tags of each page again, and is read only
  when the same bongo code saved it.
The incremental bench listed public/ before each build to count
the files that it wrote, which warmed the cache of the folder for
the build. It now lists it once after the build, by mtime.
A build reads only the sources whose size or mtime changed, and
trusts the memo's list of public/. A stray file there stays until
--fresh, and a symlink is deleted when a write goes through it.
A quiet run after the memo began to skip reads of unchanged
sources and the listing of public/, with the bench that no longer
warms the cache of public/.
The full GC before the writes lowers the peak RSS of a large
render, but costs ~12 ms with the memo on the heap. It now runs
only when the build rendered 1,000 pages or more.
The memo keeps a hash of each page's entry in the registries, so a
page whose source it had joins them without JSON and a hash of its
record.
The size report takes the size of each file that the build has a
stat of: the pages it checked or wrote, and the files of walk 1.
It stats only the rest. Bun gzips the listed assets at once, and
Node loads zlib only for the report.
The memo keeps two marks for each asset: a hash of the name,
exports, and image of its output, and of its content when a page
inlines it. A kept page renders again when a mark of its own asset
changed, so a build with no changed asset checks no page, and the
memo keeps no signature for each page.
A kept page no longer registers its assets or keeps its files one
by one: each asset of the kept pages registers once, and their
files are kept at once, before any page renders. A claim goes from
the file up, as far as a folder that is claimed already.
Each item is a row, not an object, so the memo holds no key names.
A heading keeps its html only where it differs from its text, an
output is relative to public/, pages share one table of their
placeholder lists, and hashes are base64url. The pages that share a
list of placeholders share one array of it once loaded.
The final numbers of #66, and an interleaved A/B of each step that
cut the time of a small change, since whole bench runs swing by as
much as one step gains.
rewriteTransitionAttrs ran a regex on every opening tag of every
page, about 55 ms per 1,000 pages, though most pages have no
transition attribute. One search for transition:name or
transition:animate now returns a page without either as it is,
which is what the rewrite gave for it.
Full builds, docs, the incremental steps, and dev after the guard
on the transition scan, and its A/B for a --fresh build.
@lukeed
lukeed merged commit 8367a59 into main Oct 17, 2026
1 of 3 checks passed
@lukeed lukeed mentioned this pull request Oct 18, 2026
6 tasks done
@lukeed
lukeed deleted the incremental branch October 19, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: render only what changed since the last build

1 participant