Skip to content

build: render only what changed since the last build #66

Closed

Description

@lukeed

bongo build renders every page on each run. On a large site, a run after a one-line edit costs the same as the first run: about 4 s for the 10,000-page site of bun run bench (#56). This issue makes a build render again only the pages whose output can change, and keeps the output byte for byte the same as a full build.

Prerequisite

#60: bongo build writes over public/ and deletes only stale files, so an unchanged page can keep its file.

Cache

Keep the state of the last good build in node_modules/.cache/bongo/, next to the image and render caches:

  • A hash of each global input (see below).
  • For each content file: a hash of its source, its frontmatter signature, the record that $pages holds for it (path, url, title, summary, section, tags, headings, params, alternates), its output path, the placeholders of its assets, its renders, and what it read (see below).
  • The output name and the hash of each asset.
  • The list of output files.

A clean checkout, such as on CI, has no cache, so it builds everything.

What a page reads

Template values come from code, so bongo cannot know them ahead of time. It can see them while a page renders. Give each page's scope getters for $pages, $section, and $tags, which record each read. Partials see the scope of the page that renders them, so their reads count for that page too. Record, for each page:

  • whether it read $pages;
  • whether it read $section, and which section;
  • whether it read $tags.

When to render again

  1. Everything, when a global input changes: the version of bongo, the config file and each local file it imports, each file in data/, layouts/, and partials/, the versions of the plugins and loaders, and the options of the run, such as --minify.
  2. A page whose source changed.
  3. Each page that read a registry that changed. A page is added or deleted, or its record changes, such as a new title, tags, or headings. Then render again each page that read $pages; each page that read $section, for each section that changed; and each page that read $tags, when a tag list changed. Adding one post thus renders that post, its section index, and the pages around it, not the whole site.
  4. Each page that uses an asset whose output name or content changed, such as a root stylesheet. This can render the page again, or put the new names into HTML that the cache kept with its placeholders.
  5. Output files and data modules, on every build. They read $pages, and there are few of them.

A page that does not render again keeps its file in public/, unless the file is missing or was changed outside bongo.

Limits

  • A template that reads a value bongo does not track, such as Date.now(), an environment variable, or a file that a TypeScript partial opens, keeps its last output until something above renders it again. Document this, and add a flag for a full build, such as --fresh.
  • $hooks.transform runs only on pages that render again.

Measure

Add scenarios to bun run bench: no change, one body edit, one frontmatter edit, one new page, an edit to layouts/html.hbs, and an edit to the root stylesheet. Report the time and peak RSS of each.

Acceptance

  • For each scenario, the files of an incremental build are byte for byte the same as those of a full build of the same sources.
  • A change to any global input gives a full build.
  • With no change, a build of the 10,000-page bench site takes a small part of a full build.

Activity

  1. added
    enhancement
    on Oct 15, 2026
  2. lukeed commented on Oct 15, 2026

    @lukeed
    OwnerAuthor

    Design, with the decisions from the discussion: one engine for bongo build and dev, a hash of every source, stable asset names in dev, and --fresh.

    Memo

    After each build, bongo keeps a memo of it. bongo build saves it in node_modules/.cache/bongo/build/. Dev keeps it in memory. It holds:

    • A global key: a hash of the bongo code, the runtime version, the options of the run (--minify, dev), the config and each local file it imports, each file in data/, layouts/, and partials/, and the nearest lockfile, which covers plugin versions. If it changes, or --fresh is given, the build renders everything.
    • For each content file: a hash of its source, and the record that walk 1 made for it: kind, paths, params, title, summary, tags, and headings. A file whose hash matches does not run its loaders. Its record goes into $pages as it is, and its body is loaded only if the page must render again.
    • For each page: which registries it read, the asset registrations of its placeholders, its renders, its <bongo:alternate> elements, the files that $assets.load read (with hashes), a signature of its assets after the flush, and the size and mtime of its output file.
    • A hash of $pages, of each section, and of $tags, from the records.

    What a page reads

    tempura reads every declared value as a template starts, so getters cannot see what a template uses. Instead, a page reads a registry if its .hbs body, a layout of its chain, or a partial that it called names $pages, $section, or $tags. A partial in TypeScript or JavaScript counts as reading all three. Templates can reach a registry only by its name, so this can over-count, but it never misses. It also costs nothing per access, unlike a Proxy on each array.

    When a page renders again

    A page renders again when the global key changed, its source changed, a registry that it read has a new hash, a file that it loaded changed, or its output file is missing or was changed outside bongo. Otherwise it keeps its file, and its asset registrations, renders, and alternates are replayed, so the bundler, output files, data modules, and the sweep see the whole site.

    After the bundler flush, a page whose assets got new output names renders again too. In dev, scripts and stylesheets keep stable names, so an edit to a stylesheet changes no page; inline assets count by content.

    Output files and data modules run on every build, since they read $pages, and there are few of them. $hooks.transform runs only on pages that render again.

    Dev's narrow rebuild (only, and the frontmatter signature that promotes it) is replaced by this engine.

    Limits

    A template that reads a value the memo does not track, such as Date.now(), an environment variable, or a file that a partial opens, keeps its last output until something above renders it again. --fresh builds everything.

    Measure

    bun run bench adds build scenarios, each checked byte for byte against a fresh build of the same sources: no change, a body edit, a frontmatter edit, a new page, a layout edit, and a stylesheet edit. The dev scenario adds a stylesheet edit and a new page.

  3. added 2 commits that reference this issue on Oct 17, 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