Repository navigation
feat: incremental builds - #69
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #66.
bongo buildandbongo devnow render only the pages that a change reaches. The other pages keep their files from the last build.bongo buildkeeps a record of its last good build innode_modules/.cache/bongo/memo.json;bongo devkeeps it in memory.--freshrenders every page.What renders again
$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.$assets.loadfile changed.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.$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).public/changed or is gone.data/,layouts/,partials/, the lockfile, the bongo code, the runtime, or--minifychanges. Output files and data modules render on every build.How
public/, sobongo builddoes 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. Emptyingpublic/deletes the memo.bongo build, the memo's hashes of each asset's sources catch most of these before walk 1, so those pages render once.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 thatbongo build -C <dir>ran in. The bench site's hash changes once, to8a3eb4b55617cb67.fix: default minify to false: the API leftminifyundefined while the CLI passesfalse, 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 walkspublic/; each file that a tag names is checked once in a build; each asset's placeholder is hashed once.perf: guard transition scan:rewriteTransitionAttrsran a regex on every opening tag of every page, though most pages have no transition attribute. One search fortransition:nameortransition:animatenow skips such a page. A--freshbuild 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--freshbuild.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.mdhas that table and the full tables, and the bench has a newincrementaltarget.Trade-offs
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.transformruns only for the pages that render.public/stays until--fresh.Test plan
bun test(833 pass),bunx tsc -p .,bunx tsc -p build,bun run buildbongo buildand in dev, renders the expected pages and writes the bytes of a fresh buildpublic/, memo deleted on failure, inline marks, memo round trip: each test fails with its feature switched offbun run bench: every incremental step matches--fresh