From 046832c560f10734cca225c0b6c1eab35ca1c7bf Mon Sep 17 00:00:00 2001 From: Kuba Sunderland-Ober Date: Wed, 18 Nov 2026 14:47:17 +0100 Subject: [PATCH 1/9] tbdocs: buildInfo is one git process that the main thread starts and bookPayload waits for, none without a PDF; addinFiles starts the add-in's file listing early, one process, so addinProject no longer waits for git at the build's end --- builder/addin-project.mjs | 41 +++++++++++++++++++------- builder/build-info.mjs | 24 +++++++-------- builder/cpu-worker.mjs | 8 +---- builder/gantt.mjs | 2 +- builder/sab-scheduler.mjs | 1 - builder/tbdocs.mjs | 58 ++++++++++++++++++++++++++++--------- test/addin-project.test.mjs | 18 +++++++++++- 7 files changed, 105 insertions(+), 47 deletions(-) diff --git a/builder/addin-project.mjs b/builder/addin-project.mjs index 8d951e270..275192c9e 100644 --- a/builder/addin-project.mjs +++ b/builder/addin-project.mjs @@ -73,12 +73,30 @@ export function addinProjectOf(config) { return { src: String(e.src), dest: posix(String(e.dest)).replace(/^\/+/, "") }; } -// The files git lists under `dir`, relative to it, with forward slashes. -async function gitFiles(dir, ...args) { - const { stdout } = await exec("git", ["-C", dir, "ls-files", "-z", ...args, "--", "."], { - maxBuffer: 16 * 1024 * 1024, - }); - return stdout.split("\0").filter(Boolean).sort(byCodePoint); +/** + * The files of the add-in's folder as git sees them, relative to it, with forward + * slashes: those it tracks, and those it does not track and does not ignore. + * + * One process lists both: `-t` puts a status letter and a space before each + * path, `?` for a file git does not track. On Windows a `git` takes a few tenths + * of a second to start, so the build starts this long before it packs the + * project (the addinFiles task) and passes the promise to packAddinProject. + * + * @returns {Promise<{tracked: string[], untracked: string[]}>} + */ +export async function listAddinFiles(dir) { + const { stdout } = await exec( + "git", + ["-C", dir, "ls-files", "-z", "-t", "--cached", "--others", "--exclude-standard", "--", "."], + { maxBuffer: 16 * 1024 * 1024 }, + ); + const tracked = new Set(); + const untracked = new Set(); + for (const entry of stdout.split("\0")) { + if (!entry) continue; + (entry[0] === "?" ? untracked : tracked).add(entry.slice(2)); + } + return { tracked: [...tracked].sort(byCodePoint), untracked: [...untracked].sort(byCodePoint) }; } const isHelp = (rel) => rel.toLowerCase().startsWith(HELP_DIR); @@ -96,12 +114,14 @@ function lf(bytes) { * @param {string} [o.symbols] the symbol index to pack in place of the folder's copy * @param {Buffer} [o.archive] the offline tree's archive this build wrote, packed as * Resources/HELP/site.zip; none when absent, whatever site.zip is on the disk + * @param {Promise<{tracked: string[], untracked: string[]}>} [o.listing] what + * listAddinFiles(dir) returned, when the caller started it earlier * @returns {Promise<{bytes: Buffer, files: string[], untracked: string[]}>} the * project file, the files packed, and the files git does not track that were * left out (Resources/HELP/ aside) */ -export async function packAddinProject({ dir, symbols, archive = null }) { - const [tracked, untracked] = await Promise.all([gitFiles(dir), gitFiles(dir, "--others", "--exclude-standard")]); +export async function packAddinProject({ dir, symbols, archive = null, listing = null }) { + const { tracked, untracked } = await (listing ?? listAddinFiles(dir)); const files = []; for (const rel of tracked) { if (isHelp(rel)) continue; @@ -139,11 +159,12 @@ export async function packAddinProject({ dir, symbols, archive = null }) { * @param {Buffer} [o.archive] the offline archive this build wrote, if it wrote one * @param {string[]} o.roots the trees to write into * @param {string} o.rel the file's path in each tree + * @param {Promise} [o.listing] listAddinFiles(dir), started earlier * @returns {Promise<{rel: string, bytes: number, files: number, archived: boolean, untracked: string[], roots: number, ms: number}>} */ -export async function writeAddinProject({ dir, symbols, archive = null, roots, rel }) { +export async function writeAddinProject({ dir, symbols, archive = null, roots, rel, listing = null }) { const t0 = Date.now(); - const packed = await packAddinProject({ dir, symbols, archive }); + const packed = await packAddinProject({ dir, symbols, archive, listing }); for (const root of roots) { const out = path.join(root, ...rel.split("/")); await fs.mkdir(path.dirname(out), { recursive: true }); diff --git a/builder/build-info.mjs b/builder/build-info.mjs index ce7811636..f53b7f3d4 100644 --- a/builder/build-info.mjs +++ b/builder/build-info.mjs @@ -1,8 +1,12 @@ -// Phase 2 build-info capture. Two `git` shell-outs (parallel) to -// produce { commit, commitDate } for the PDF title page. Falls back to +// Phase 2 build-info capture. One `git` shell-out to produce +// { commit, commitDate } for the PDF title page. Falls back to // "unknown" placeholders when git is missing or this isn't a repo // (tarball install) so the build never aborts on it. // +// One process, not two: on Windows a `git` takes a few tenths of a second to +// start, more while the lanes boot. `%h` is the abbreviation `rev-parse +// --short HEAD` prints. +// // See builder/PLAN-2.md §5.9. Ports: _plugins/build-info.rb. import { execFile } from "node:child_process"; @@ -11,18 +15,12 @@ import { promisify } from "node:util"; const exec = promisify(execFile); export async function captureBuildInfo() { - const [commit, commitDate] = await Promise.all([ - git("rev-parse", "--short", "HEAD"), - git("log", "-1", "--format=%cs"), - ]); - return { commit, commitDate }; -} - -async function git(...args) { try { - const { stdout } = await exec("git", args); - return stdout.trim(); + const { stdout } = await exec("git", ["log", "-1", "--format=%h %cs"]); + const [commit, commitDate] = stdout.trim().split(" "); + if (commit && commitDate) return { commit, commitDate }; } catch { - return "unknown"; + // Not a repository, or no git. } + return { commit: "unknown", commitDate: "unknown" }; } diff --git a/builder/cpu-worker.mjs b/builder/cpu-worker.mjs index 30329c206..0bc8847bf 100644 --- a/builder/cpu-worker.mjs +++ b/builder/cpu-worker.mjs @@ -20,7 +20,7 @@ import { unpackShared } from "./sab-broadcast.mjs"; // second boot bar. The names are module-level bindings that loadRest fills, so // that the handlers read as they would with static imports. // biome-ignore format: one module per line -let compileLightScss, compileDarkScss, regenerateDot, captureBuildInfo, deflateGroup, writePdf, unpackBookPayload, +let compileLightScss, compileDarkScss, regenerateDot, deflateGroup, writePdf, unpackBookPayload, createMarkdownIt, renderPhase, markdownCopy, markdownCopyRel, navTreeVersion, renderFullNav, templatePhase, withOnlineNav, withPartialNav, deriveSearchEntries, entryKeys, labelKey, packSearchEntries, readSearchEntries, @@ -33,7 +33,6 @@ const loadRest = () => const start = Date.now(); ({ compileLightScss, compileDarkScss } = await import("./scss.mjs")); ({ regenerateDot } = await import("./dot.mjs")); - ({ captureBuildInfo } = await import("./build-info.mjs")); ({ deflateGroup } = await import("./help-archive-step.mjs")); ({ writePdf } = await import("./pdf.mjs")); ({ unpackBookPayload } = await import("./book-payload.mjs")); @@ -250,11 +249,6 @@ const handlers = { return { dotStats }; }, - async buildInfo() { - const buildInfo = await captureBuildInfo(); - return { buildInfo }; - }, - // The contributed packages' test projects and published tools, packed in // memory (package-tests.mjs) from the package_tests entry that config // broadcast. The bytes go back to the main thread, where downloadSizes reads diff --git a/builder/gantt.mjs b/builder/gantt.mjs index 0346dd322..21d343a7a 100644 --- a/builder/gantt.mjs +++ b/builder/gantt.mjs @@ -45,7 +45,7 @@ const BAR_PAD = 4; // its own `ganttSection` is charted there instead. // biome-ignore format: a table, one entry per line export const GANTT_SECTION = { - config: "Seeds", buildInfo: "Seeds", scssLight: "Seeds", scssDark: "Seeds", scss: "Write", dot: "Spine", + config: "Seeds", buildInfo: "Seeds", addinFiles: "Seeds", scssLight: "Seeds", scssDark: "Seeds", scss: "Write", dot: "Spine", highlighterInit: "Seeds", loadData: "Seeds", discoverList: "Spine", discover: "Spine", vendorAssets: "Spine", nav: "Spine", markdownInit: "Spine", buildInit: "Spine", resolveBookChapters: "Spine", diff --git a/builder/sab-scheduler.mjs b/builder/sab-scheduler.mjs index dc061e1f6..e190a98b1 100644 --- a/builder/sab-scheduler.mjs +++ b/builder/sab-scheduler.mjs @@ -34,7 +34,6 @@ export const HANDLERS = { scssLight: 3, scssDark: 4, dot: 5, - buildInfo: 6, render: 7, writePdf: 9, checkBook: 10, diff --git a/builder/tbdocs.mjs b/builder/tbdocs.mjs index ce03380bc..f8a28aa0b 100644 --- a/builder/tbdocs.mjs +++ b/builder/tbdocs.mjs @@ -106,7 +106,8 @@ import { normalizeBaseurl } from "./url.mjs"; // build without --check pays nothing. import { deriveTreeRels } from "./check-tree.mjs"; import { syncAddinIndex } from "./addin-index.mjs"; -import { addinProjectOf, formatAddinProject, writeAddinProject } from "./addin-project.mjs"; +import { addinProjectOf, formatAddinProject, listAddinFiles, writeAddinProject } from "./addin-project.mjs"; +import { captureBuildInfo } from "./build-info.mjs"; import { formatPackageTests, packageTestRels, packageTestsOf, writePackageTests } from "./package-tests.mjs"; import { finishHelpArchive, @@ -271,16 +272,40 @@ const TASKS = { }, }, - // Git rev-parse / log shell-outs, for the book's title page: bookPayload - // waits for them, and nothing on the way to the first render does. Like the - // other early lane tasks it waits for discoverList, so that the first lanes - // up read the source tree. + // Starts the git process whose answer the book's title page states, and does + // not wait for it: bookPayload does, long after it has answered. On Windows + // a git takes a few tenths of a second to start, and up to two seconds while + // the lanes boot; as a lane task it held a lane for that long, for no work of + // the lane's. After dispatch, so that the process starts once the main + // thread's way to the first render is behind it. A build that writes no PDF + // (--serve, --no-pdf, --dry-run) starts none. buildInfo: { - expected: ["discoverList"], - handler: "buildInfo", - submit(out, state) { - state.site.buildInfo = out.buildInfo; + expected: ["dispatch"], + runOnMain: true, + execute(_, ctx, state) { + state.buildInfoPending = ctx.opts.dryRun || skipsPdf(ctx, state) ? null : captureBuildInfo(); + return null; + }, + submit() {}, + }, + + // Starts the git process that lists the help add-in's files, and does not + // wait for it: addinProject does, at the end of the build, where the listing + // used to take a few tenths of a second on Windows with nothing else left to + // run. A rejection is addinProject's to report, so it is marked as handled + // here. + addinFiles: { + expected: ["dispatch"], + runOnMain: true, + execute(_, ctx, state) { + const addin = addinProjectOf(state.site.config); + state.addinListing = null; + if (!addin || ctx.opts.dryRun) return null; + state.addinListing = listAddinFiles(path.resolve(ctx.srcRoot, addin.src)); + state.addinListing.catch(() => {}); + return null; }, + submit() {}, }, // Sass compilation split across two workers so light + dark run in parallel. @@ -804,8 +829,9 @@ const TASKS = { // two parallel halves: nav (sidebar) + buildInit (config-only chrome). dispatch: { // buildInfo is not here: the book's title page alone states the commit, so - // bookPayload waits for it. Its two git processes take up to 0.6 s in a - // one-off build on Windows, and every render waited for them. + // bookPayload waits for it. Its git process takes up to 0.6 s in a + // one-off build on Windows, and every render waited for it. The buildInfo + // task waits for this one, only to start the process after it. expected: ["nav", "buildInit", "dot", "deriveRedirects", "markdownInit"], runOnMain: true, async execute( @@ -1450,7 +1476,7 @@ const TASKS = { // fixtures) packs nothing. A failure is reported and fails the build; the // trees are still written. addinProject: { - expected: ["symbolIndex", "prepDest", "helpArchive"], + expected: ["symbolIndex", "prepDest", "helpArchive", "addinFiles"], runOnMain: true, async execute({ symbolIndex, helpArchive }, ctx, state) { const addin = addinProjectOf(state.site.config); @@ -1462,6 +1488,7 @@ const TASKS = { archive: helpArchive?.zip ?? null, roots: [ctx.destRoot], rel: addin.dest, + listing: state.addinListing, }); } catch (err) { return { failed: true, rel: addin.dest, error: err.message }; @@ -1519,9 +1546,12 @@ const TASKS = { // states (state.site.buildInfo), which nothing before this reads. expected: ["flushJoin", "renderJoin", "dot", "resolveBookChapters", "buildInfo"], runOnMain: true, - execute(_, ctx, state) { + async execute(_, ctx, state) { const skip = !!ctx.opts.dryRun || skipsPdf(ctx, state); - if (!skip) prerenderPartText(state.site.bookData, state.site.markdown); + if (!skip) { + state.site.buildInfo = await state.buildInfoPending; + prerenderPartText(state.site.bookData, state.site.markdown); + } return packBookPayload({ pages: state.pages, staticFiles: state.staticFiles, diff --git a/test/addin-project.test.mjs b/test/addin-project.test.mjs index e11141de0..0d9fff1bf 100644 --- a/test/addin-project.test.mjs +++ b/test/addin-project.test.mjs @@ -26,7 +26,13 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { after, describe, test } from "node:test"; import { crc32, inflateRawSync } from "node:zlib"; -import { addinProjectOf, formatAddinProject, packAddinProject, writeAddinProject } from "../builder/addin-project.mjs"; +import { + addinProjectOf, + formatAddinProject, + listAddinFiles, + packAddinProject, + writeAddinProject, +} from "../builder/addin-project.mjs"; import { downloadsKept, helpArchiveSkips } from "../builder/help-archive-step.mjs"; import { checkHelpArchive, @@ -129,6 +135,16 @@ describe("the help add-in's project file", () => { assert.deepEqual(untracked, ["Sources/Scratch.twin"]); }); + test("packs from a listing made earlier as it does from its own", async () => { + const dir = fixture("listed", TRACKED, { "Sources/Scratch.twin": "Module Scratch\nEnd Module\n" }); + const listing = listAddinFiles(dir); + assert.deepEqual(await listing, { tracked: Object.keys(TRACKED).sort(), untracked: ["Sources/Scratch.twin"] }); + const own = await packAddinProject({ dir }); + const given = await packAddinProject({ dir, listing }); + assert.ok(given.bytes.equals(own.bytes), "the two packs differ"); + assert.deepEqual(given.untracked, own.untracked); + }); + test("packs the index it is given in place of the folder's copy, and the copy without one", async () => { const dir = fixture("symbols", TRACKED); const given = filesIn((await packAddinProject({ dir, symbols: '{"built":true}\n' })).bytes); From 5fdb9291767a13fcc132e1fc0b5d5938120efbf6 Mon Sep 17 00:00:00 2001 From: Kuba Sunderland-Ober Date: Wed, 18 Nov 2026 14:53:49 +0100 Subject: [PATCH 2/9] docs: buildInfo and addinFiles start git from the main thread, and what awaits each --- WIP.Build.md | 58 ++++++++++++++++++++++++--- docs/Documentation/Builder.md | 11 ++--- docs/Documentation/Extending.md | 2 +- docs/Documentation/Pipeline-Stages.md | 32 +++++++++------ 4 files changed, 79 insertions(+), 24 deletions(-) diff --git a/WIP.Build.md b/WIP.Build.md index ae1ff7b22..3af2de3b1 100644 --- a/WIP.Build.md +++ b/WIP.Build.md @@ -176,8 +176,8 @@ What makes it worth doing, and what to keep when changing it: would take them and load the second stage, and the pieces would wait for a lane. The listing takes a few hundredths of a second, less than a lane takes to start. The pieces have the highest priority, so the first lanes that look take them. - `buildInfo` waits too, since nothing early needs it: see - [dispatch does not wait for buildInfo](#dispatch-does-not-wait-for-buildinfo). + `buildInfo` is no lane task since: see + [git is started by the main thread and awaited where it is needed](#git-is-started-by-the-main-thread-and-awaited-where-it-is-needed). - **Two pieces below eight CPUs, four from eight on** (`discoverPieces`; owner, 2026-11-18). On four CPUs the other two lanes compile the stylesheets meanwhile; with four pieces there `dot` and `packTests` queued behind the reads and `dispatch`, which @@ -258,9 +258,8 @@ late. In a serve rebuild it took 0.03 to 0.3 s, with the same effect. On CI's Li was done long before. `bookPayload` waits for it now, which reads `state.site.buildInfo` and runs after the -render; the shared payload and the lanes' site object hold it no longer. `buildInfo` -also waits for `discoverList`, as the other early lane tasks do, so that it does not -take a lane the source tree's pieces want. +render; the shared payload and the lanes' site object hold it no longer. (`buildInfo` +was a lane task then; it is a main-thread task now, see the next section.) Measured on the dev box, with four pieces of the source tree as well (the two changes were measured together), the first render starting at: @@ -281,6 +280,55 @@ carries the levels, which takes 6 ms alone on its first call where it took 19 to In a build the task still reads 29 to 69 ms (28 to 64 ms before): its time there is not its own work but the main thread's share of a machine whose lanes are all booting. +### git is started by the main thread and awaited where it is needed + +On Windows a `git` process takes 0.15 to 1.0 s to start and answer, alone on a quiet +machine, and up to 2.3 s while the lanes boot. The build asks `git` two things, and both +waited for it in the wrong place: + +- **`buildInfo` was a lane task.** A lane that awaits a process does no other work, so + one lane was out of the build for 0.47 to 0.88 s on sixteen CPUs and 0.50 to 2.33 s on + four, where render starts at about 1.5 s. It was also two processes + (`rev-parse --short HEAD` and `log -1 --format=%cs`) where `log -1 --format="%h %cs"` + answers both. +- **`addinProject` listed the add-in's files at the very end of the build**, two + `git ls-files` after `helpArchive`, with nothing else left to run: 0.21 to 1.55 s in + a one-off build, 0.22 to 0.55 s in a serve rebuild. + +Both are now main-thread tasks that start one process and return: `buildInfo` keeps +the promise in `state.buildInfoPending` and `bookPayload` awaits it; `addinFiles` +keeps `state.addinListing` (`listAddinFiles`: one `git ls-files -t --cached --others`, +where `?` marks a file git does not track) and `addinProject` awaits it. By then each +has long answered. What to keep: + +- **A main-thread task must not await the process itself**: the main thread finishes a + task before it claims the next, so the await belongs in the task that needs the + answer, which runs late. +- **Both wait for `dispatch`**, only so that the processes start after the main + thread's work for the first render. Starting a process takes the main thread 3 to + 31 ms. +- **A build that writes no PDF starts no `buildInfo` process** (`--serve`, `--no-pdf`, + `--dry-run`): only the title page reads it. +- **The chart shows the two tasks as slivers**, not how long `git` took. The add-in's + line in the build's report still gives `addinProject`'s time. +- `compare_trees` replaces the title page's build line, so check the commit there by + reading `_site-pdf/book.html` after a change to `build-info.mjs`. + +Measured on the dev box, three runs of each, base against branch in the same session: + +| | before | since | +|---|---|---| +| `addinProject`, one-off, 16 CPUs | 0.48 to 0.64 s | 0.08 to 0.09 s | +| `addinProject`, one-off, 4 CPUs | 0.21 to 1.55 s | 0.09 to 0.10 s | +| `addinProject`, serve rebuild (builds 2 to 5) | 0.22 to 0.55 s | 0.01 to 0.02 s | +| first render, one-off, 16 CPUs | 0.81 to 0.95 s | 0.70 to 0.88 s | +| first render, one-off, 4 CPUs | 1.38 to 1.69 s | 1.07 to 1.34 s | +| whole build, 16 CPUs | 9.2 to 10.8 s | 8.6 to 9.4 s | +| whole build, serve rebuild (builds 2 to 5) | 3.96 to 4.66 s | 3.55 to 4.27 s | + +The whole build on four CPUs is within the runs' noise (15.2 to 18.2 s against 15.5 to +17.3 s). Not measured: CI, where `git` is quick and little should show. + ### What markdownInit is made of Every render waits for `markdownInit`. On the dev box it took 117 to 151 ms in a one-off diff --git a/docs/Documentation/Builder.md b/docs/Documentation/Builder.md index d17e78da9..0ad5bdf21 100644 --- a/docs/Documentation/Builder.md +++ b/docs/Documentation/Builder.md @@ -217,7 +217,7 @@ The full layout, the allocation helper and the `readTaskMeta` / `writeTaskMeta` The pipeline has the named static tasks below, plus dynamic ones: a `render:i` and a `flush:i` for each render chunk, and the pieces of the search index and of the help archive. The Gantt chart groups them into these sections, and so does the rest of this page: -- **Seeds**: `config`, `buildInfo`, `scssLight`, `scssDark`, `highlighterInit`, `loadData` +- **Seeds**: `config`, `buildInfo`, `addinFiles`, `scssLight`, `scssDark`, `highlighterInit`, `loadData` - **Spine**: `discoverList`, `discoverRead:i`, `discover`, `vendorAssets`, `nav`, `dot`, `buildInit`, `markdownInit`, `deriveRedirects`, `deriveSitemap`, `resolveBookChapters`, `packTests`, `downloadSizes`, `packageApi` - **Render**: `dispatch`, `prepDest`, `prepPageDirs`, `render:i`, `renderJoin` - **Write**: `scss`, `flush:i`, `flushJoin`, `writeAssets`, `searchData`, `symbolIndex`, `archivePlan`, `archiveDeflate:i`, `archiveLate`, `archiveLateDeflate:i`, `helpArchive`, `addinProject`, `packageTests`, `writeAux`, `writeOffline`, `bookPayload`, `writePdf` @@ -234,10 +234,11 @@ Every static task and dependency: ### Seeds -`config` has no predecessor and starts at once; `highlighterInit` waits for `config`, and `loadData` for `highlighterInit`. `buildInfo`, `scssLight` and `scssDark` wait for `discoverList`, the listing of the source tree, so that the first workers up are free to read it (see [Spine](#spine)). The three worker tasks run while the source tree is read and the main thread prepares the render. +`config` has no predecessor and starts at once; `highlighterInit` waits for `config`, and `loadData` for `highlighterInit`. `scssLight` and `scssDark` wait for `discoverList`, the listing of the source tree, so that the first workers up are free to read it (see [Spine](#spine)). The two run while the source tree is read and the main thread prepares the render. `buildInfo` and `addinFiles` wait for `dispatch`. - `config` (main) --- reads `_config.yml` and applies CLI overrides. -- `buildInfo` (worker) --- two `git` shell-outs. Falls back to `"unknown"` on failure. Only the book's title page states the result, so `bookPayload` waits for it and the render does not. +- `buildInfo` (main) --- starts one `git` process and does not wait for it. Only the book's title page states the result, so `bookPayload` awaits it and the render does not. Falls back to `"unknown"` on failure. A build that writes no PDF starts no process. +- `addinFiles` (main) --- starts the `git` process that lists the help add-in's files and does not wait for it; `addinProject` awaits the list at the end of the build. - `scssLight` (worker) --- compiles `just-the-docs-combined.scss` against the light palette. - `scssDark` (worker) --- the same against the dark palette. - `highlighterInit` (main) --- loads the `Light.theme` + `Dark.theme` palette and emits `tb-highlight.css`. Each worker initialises its own Shiki. @@ -308,7 +309,7 @@ dispatch ┬→ render:0 ┬→ flush:0 ┐ - `indexSlices`, `indexMerge`, `indexTerms`, `searchIndex` (main) and `indexAdd:i`, `indexVectors:i` (worker) --- build the lunr index of the search entries and write `search-index.json`, the entries and their index in one file, which the search box loads instead of building the index, and the offline tree's `search-index.js`. The index is built in slices on the lanes and merged into exactly the index `lunr()` makes (see [Pipeline Stages](Pipeline-Stages#searchindex-worker)). A lane reads its slice's entries from the buffers the render lanes packed, so the main thread does not send them. `indexSlices` depends on `searchEntries`; `archiveLate` and `checkReport` wait for `searchIndex`. - `symbolIndex` (main) --- writes `tB/symbols.json`, the [symbol index](Building#the-symbol-index) the IDE help add-in reads, from what `symbolPlace` placed, and returns the index's URLs for the drift guard that `runBuild` runs at the end. Depends on `symbolPlace` and `prepDest`. `checkReport` and `addinProject` wait for it. - `archivePlan`, `archiveLate`, `helpArchive` (main) and `archiveDeflate:i`, `archiveLateDeflate:i` (worker) --- write `add-in/Resources/HELP/site.zip`, the archive of the offline tree that the IDE help add-in embeds (see [Build and Generation Tools](Tools-Build#the-help-archive) and [Pipeline Stages](Pipeline-Stages#helparchive-worker)). `archivePlan` depends on `flushJoin`, `scss` and `writeOffline`, which between them write the whole offline tree but `search-index.js`, and the lanes deflate that tree while the search index is built. `archiveLate` depends on `searchIndex` and has the lanes deflate `search-index.js`, in pieces. `helpArchive` writes the zip from what the lanes deflated. The archive leaves out the sections `HELP_ARCHIVE_SKIP` lists, `BuildInfo.html` and its chart among them, and is made before the Gantt chart is injected. It is made only for a `docs` build into the default `--dest`, `docs/_site`, with an offline tree, and not under `--serve`, `--dry-run` or `--no-help-archive`. After the chart is injected, `runBuild` checks that the offline tree still lists the archive's files and differs from it in `BuildInfo.html` and `assets/images/gantt.svg` alone. -- `addinProject` (main) --- packs the help add-in's source folder, `add-in/`, into `tbDocsHelp.twinproj` and writes it into the online tree at the path `_config.yml`'s `addin_project` names (see [Build and Generation Tools](Tools-Build#the-help-add-ins-project-file)). The files are those git tracks there, the symbol index is the one `symbolIndex` wrote, and `Resources/HELP/site.zip` is the archive `helpArchive` wrote, if any. Depends on `symbolIndex`, `prepDest` and `helpArchive`; `checkReport` waits for it. Does nothing under `--dry-run` or for a config that declares no download. +- `addinProject` (main) --- packs the help add-in's source folder, `add-in/`, into `tbDocsHelp.twinproj` and writes it into the online tree at the path `_config.yml`'s `addin_project` names (see [Build and Generation Tools](Tools-Build#the-help-add-ins-project-file)). The files are those git tracks there, the symbol index is the one `symbolIndex` wrote, and `Resources/HELP/site.zip` is the archive `helpArchive` wrote, if any. Depends on `symbolIndex`, `prepDest`, `helpArchive` and `addinFiles`, whose list of files it awaits; `checkReport` waits for it. Does nothing under `--dry-run` or for a config that declares no download. - `writeAux` (main) --- writes redirect stubs, the sitemap, robots.txt, llms.txt and the online tree's `nav.html`, the whole nav tree, which `linkJoin` checks with the stubs. Depends on `writeAssets`, `searchData`, `flushJoin`, `renderJoin` (llms.txt takes each page's note from its `renderedContent`), `deriveRedirects`, `deriveSitemap`. - `writeOffline` (main) --- produces `_site-offline/`. `render:i` and `flush:i` already computed and wrote the per-page HTML, so this task does the cross-cutting work: CSS url() rewriting, the just-the-docs.js AST patch, the offline `nav.js`, theme assets and redirect stubs. The offline search index, `search-index.js`, is `searchIndex`'s. - `bookPayload` (main) --- packs what the book needs into one shared buffer and broadcasts it to every worker. It renders each part's subtitle and intro first, because markdown-it cannot cross to a worker, and replaces every page reference in `bookData` with the page's index in the page list, so the worker resolves it back to the same object. Depends on `flushJoin` (`renderedContent` is filled), `renderJoin`, `resolveBookChapters` (`bookData._chapters` is set) and `dot` (diagram SVGs are in `staticFiles`). The broadcast is posted before the task is marked done, so it is queued on every lane before any lane can claim `writePdf`. Under `--dry-run`, or when the build writes no PDF tree, it packs a marker that tells `writePdf` there is nothing to write. @@ -321,7 +322,7 @@ Every task and where it runs: | Section | Task | Locus | Notes | |---|---|---|---| | Seeds | `config` | main | Trivial read; output feeds `discover` directly. | -| Seeds | `buildInfo` | worker | Two `git` shell-outs in parallel. | +| Seeds | `buildInfo`, `addinFiles` | main | Each starts one `git` process and returns; the task that needs the answer awaits it. | | Seeds | `scssLight`, `scssDark` | workers | Light + dark palettes compile concurrently. | | Seeds | `highlighterInit` | main | Palette CSS only. | | Seeds | `loadData` | main | Reads `_book.yml`. | diff --git a/docs/Documentation/Extending.md b/docs/Documentation/Extending.md index ac215f012..f15bcb444 100644 --- a/docs/Documentation/Extending.md +++ b/docs/Documentation/Extending.md @@ -218,7 +218,7 @@ Worker handlers live in `cpu-worker.mjs`. Two edits: export const HANDLERS = { warmInit: 0, renderEnvInit: 1, flush: 2, scssLight: 3, scssDark: 4, dot: 5, - buildInfo: 6, render: 7, + render: 7, writePdf: 9, checkBook: 10, indexAdd: 12, indexVectors: 13, archiveDeflate: 14, myHandler: 15, // ← new diff --git a/docs/Documentation/Pipeline-Stages.md b/docs/Documentation/Pipeline-Stages.md index ab79979bb..509d976e9 100644 --- a/docs/Documentation/Pipeline-Stages.md +++ b/docs/Documentation/Pipeline-Stages.md @@ -61,7 +61,7 @@ Each task's `execute()` or `submit()` stores its output on `state.site`; downstr |---|---|---|---| | `config` | `object` | `discover` | Parsed `_config.yml`, with CLI overrides (`--baseurl`, `--url`) already applied. | | `navTree` | `object` | `nav` | Top-level nav hierarchy. | -| `buildInfo` | `object` | `buildInfo` | `{ commit: string, commitDate: string }` from git. Both fall back to `"unknown"` outside a git repository. | +| `buildInfo` | `object` | `bookPayload` | `{ commit: string, commitDate: string }` from git, in a build that writes the PDF. Both fall back to `"unknown"` outside a git repository. | | `data` | `object` | `loadData` | `_book.yml` loaded as `{ book: … }`, or `{}` when absent. | | `bookData` | `object\|null` | `loadData` | Shortcut for `data.book`. After `resolveBookChapters`, each entry holds `_chapters` (`Page[]`) plus `_landing` / `_foreword` if declared. | | `markdown` | `MarkdownIt` | `markdownInit` | Main-thread markdown-it instance. Used only for site-level SEO; render workers build their own. | @@ -125,7 +125,7 @@ Every task is an entry in the static `TASKS` object in [`tbdocs.mjs`](https://gi export const HANDLERS = { warmInit: 0, renderEnvInit: 1, flush: 2, scssLight: 3, scssDark: 4, dot: 5, - buildInfo: 6, render: 7, + render: 7, writePdf: 9, checkBook: 10, packTests: 11, indexAdd: 12, indexVectors: 13, archiveDeflate: 14, discoverRead: 15, @@ -148,7 +148,7 @@ A task therefore never starts a worker thread or a process for its work, and nev ## Section 1 --- Seed tasks -The tasks that start the build. `config` has no predecessor and is claimable as soon as the build starts; `highlighterInit` waits for `config`, and `loadData` for `highlighterInit`. `buildInfo`, `scssLight` and `scssDark` wait for [`discoverList`](#discoverlist-main), as `dot`, `packTests` and `warmInit` do. +The tasks that start the build. `config` has no predecessor and is claimable as soon as the build starts; `highlighterInit` waits for `config`, and `loadData` for `highlighterInit`. `scssLight` and `scssDark` wait for [`discoverList`](#discoverlist-main), as `dot`, `packTests` and `warmInit` do. `buildInfo` and `addinFiles` wait for [`dispatch`](#dispatch-main), and each only starts a `git` process. ### `config` (main) @@ -158,9 +158,15 @@ config.execute({}, ctx) → { config } Reads `/_config.yml`, applies the `ctx.opts.baseurl` and `ctx.opts.url` overrides, and returns the parsed object to `discover`. `submit` broadcasts the config's `package_tests` entry to the lanes as the `"packageTests"` task data, for [`packTests`](#packtests-worker). -### `buildInfo` (worker) +### `buildInfo` (main) -Handler in `cpu-worker.mjs`: calls `captureBuildInfo()` from `build-info.mjs`, which runs two parallel `git` commands (`rev-parse --short HEAD` and `log -1 --format=%cs`). Falls back to `"unknown"` on failure. The result goes to `state.site.buildInfo`, which the book's title page alone states: [`bookPayload`](#bookpayload-main) waits for this task, and `dispatch` does not, so no render waits for `git`. +Starts `captureBuildInfo()` from `build-info.mjs`, which runs one `git` command (`log -1 --format="%h %cs"`), and keeps the promise in `state.buildInfoPending` without waiting for it. [`bookPayload`](#bookpayload-main) awaits the promise and puts the result in `state.site.buildInfo`, which the book's title page alone states. Both values fall back to `"unknown"` on failure. The task waits for `dispatch`, so that the process starts after the main thread's work for the first render, and no render waits for `git`. A build that writes no PDF (`--serve`, `--no-pdf`, `--dry-run`) starts no process. + +The task is on the main thread because a lane that waits for `git` does no other work meanwhile, and on Windows a `git` process takes a few tenths of a second to start. + +### `addinFiles` (main) + +Starts `listAddinFiles()` from `addin-project.mjs` on the help add-in's folder, which runs one `git ls-files`, and keeps the promise in `state.addinListing` without waiting for it. [`addinProject`](#addinproject-main) awaits it at the end of the build. Waits for `dispatch`, as `buildInfo` does. Does nothing under `--dry-run` or for a config that declares no download. ### `scssLight` (worker), `scssDark` (worker) @@ -207,7 +213,7 @@ Calls `listSources(srcRoot, config.exclude ?? [])` and then `cutPieces(listing, `submit()` calls `fanOut` with the pieces as payloads, handler `discoverRead`, join `discover` and the highest priority of any lane task. -The lane tasks that would otherwise be claimable before the pieces exist list `discoverList` in their `expected`: `buildInfo`, `scssLight`, `scssDark`, `dot`, `packTests` and `warmInit`. The first lanes to start therefore find the pieces and nothing else. +The lane tasks that would otherwise be claimable before the pieces exist list `discoverList` in their `expected`: `scssLight`, `scssDark`, `dot`, `packTests` and `warmInit`. The first lanes to start therefore find the pieces and nothing else. ### `discoverRead:i` (worker) @@ -566,11 +572,11 @@ The result fields: ### `addinProject` (main) ```js -addinProject.expected = ["symbolIndex", "prepDest"] -addinProject.execute({ symbolIndex }) → { rel, bytes, files, untracked, roots, ms } | { failed, rel, error } | null +addinProject.expected = ["symbolIndex", "prepDest", "helpArchive", "addinFiles"] +addinProject.execute({ symbolIndex, helpArchive }) → { rel, bytes, files, untracked, roots, ms } | { failed, rel, error } | null ``` -Writes the help add-in's project file, the download [Help Add-In](../../tB/IDE/AddIns/Help) offers (see [Build and Generation Tools](Tools-Build#the-help-add-ins-project-file)). Reads `addin_project` from the config with `addinProjectOf`, and returns `null` when the config declares none or under `--dry-run`. Otherwise calls `writeAddinProject` from `addin-project.mjs` with the add-in's folder (`src`, resolved against the source root), `symbolIndex.json` and the trees to write: the online tree, and the offline tree unless the build has none or `offline_exclude` leaves the file out of it. `dispatch` has already put `dest` in both trees' indexes and in `sitePaths`, so links to the file resolve. `checkReport` waits for this task. A failure (`git` missing, an unreadable file) is returned, not thrown, so the trees are still written; `runBuild` prints the result and fails the build on `failed`. Takes ~100 ms. +Writes the help add-in's project file, the download [Help Add-In](../../tB/IDE/AddIns/Help) offers (see [Build and Generation Tools](Tools-Build#the-help-add-ins-project-file)). Reads `addin_project` from the config with `addinProjectOf`, and returns `null` when the config declares none or under `--dry-run`. Otherwise calls `writeAddinProject` from `addin-project.mjs` with the add-in's folder (`src`, resolved against the source root), `symbolIndex.json` and the trees to write: the online tree, and the offline tree unless the build has none or `offline_exclude` leaves the file out of it. `dispatch` has already put `dest` in both trees' indexes and in `sitePaths`, so links to the file resolve. `checkReport` waits for this task. The list of files is the one [`addinFiles`](#addinfiles-main) asked `git` for (`state.addinListing`), so this task does not wait for `git` to start. A failure (`git` missing, an unreadable file) is returned, not thrown, so the trees are still written; `runBuild` prints the result and fails the build on `failed`. Takes ~100 ms. ### `writeAux` (main) @@ -869,7 +875,7 @@ Both HTML escapers convert a value that is not a string with `String` first. | Symbol | Signature | Description | |---|---|---| -| `captureBuildInfo` | `() → Promise<{ commit, commitDate }>` | Runs two parallel `git` commands. Returns `"unknown"` on failure. | +| `captureBuildInfo` | `() → Promise<{ commit, commitDate }>` | Runs one `git` command. Returns `"unknown"` for both on failure. | ### `data.mjs` @@ -1132,8 +1138,9 @@ The one definition of the site search's lunr index: its fields and boosts (`FIEL | Symbol | Signature | Description | |---|---|---| | `addinProjectOf` | `(config) → { src, dest } \| null` | The download `_config.yml`'s `addin_project` declares, `dest` without a leading slash; `null` unless both ends are given. | -| `packAddinProject` | `({ dir, symbols }) → Promise<{ bytes, files, untracked }>` | Packs the files `git ls-files` lists in `dir`, as the working folder holds them, less `Resources/HELP/`, with CRLF made LF outside `Resources/`, and `symbols` in place of `Resources/SYMBOLS/symbols.json` when given. Packs them in memory with `packFiles` from `scripts/impexp.mjs`, which gives the bytes `importProject` would give for the same files in a folder. `untracked` lists the files git does not track that were left out. Throws when git fails or tracks no `Settings`. | -| `writeAddinProject` | `({ dir, symbols, roots, rel }) → Promise<{ rel, bytes, files, untracked, roots, ms }>` | Packs once and writes the file at `rel` in each of `roots`. | +| `listAddinFiles` | `(dir) → Promise<{ tracked, untracked }>` | The files of `dir` that git tracks, and those it neither tracks nor ignores, from one `git ls-files`. | +| `packAddinProject` | `({ dir, symbols, listing }) → Promise<{ bytes, files, untracked }>` | Packs the files `listing` names, or those `listAddinFiles(dir)` returns when it is given none, as the working folder holds them, less `Resources/HELP/`, with CRLF made LF outside `Resources/`, and `symbols` in place of `Resources/SYMBOLS/symbols.json` when given. Packs them in memory with `packFiles` from `scripts/impexp.mjs`, which gives the bytes `importProject` would give for the same files in a folder. `untracked` lists the files git does not track that were left out. Throws when git fails or tracks no `Settings`. | +| `writeAddinProject` | `({ dir, symbols, roots, rel, listing }) → Promise<{ rel, bytes, files, untracked, roots, ms }>` | Packs once and writes the file at `rel` in each of `roots`. | | `formatAddinProject` | `(result, dirLabel, indent) → string` | The line `runBuild` prints, and a second naming any untracked file left out. | ### `page-baseline.mjs` @@ -1211,7 +1218,6 @@ The handler table is built from the imported `HANDLERS` constant: | `flush` | inline | Drains the next `_pendingFlush` batch to disk. | | `scssLight` / `scssDark` | `scss.mjs` | Light/dark palette compile. | | `dot` | `dot.mjs` | `regenerateDot` over `srcRoot`. | -| `buildInfo` | `build-info.mjs` | `captureBuildInfo`. | | `packTests` | `package-tests.mjs` | `packAllPackageTests` over the `"packageTests"` task data; imports the module when it runs. | | `render` | inline | Five-stage chunk render: `renderPhase` → `computeChunkSeo` → `templatePhase` → offline → `deriveSearchEntries`. | | `indexAdd` | `search-index.mjs` | `addSlice` over its slice's entries, which `sliceDocs` reads from the `"indexEntries"` task data as the plan in its `fanOutPayload` says; keeps the builder in `_indexSlices` for `indexVectors`. | From 7f2eba58777b1f329ddcfa52205226d18520e1f5 Mon Sep 17 00:00:00 2001 From: Kuba Sunderland-Ober Date: Wed, 18 Nov 2026 14:59:42 +0100 Subject: [PATCH 3/9] help archive: a file deflated in pieces, the offline search index, is at level 6; whole files stay at level 9 --- lib/help-archive.mjs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/help-archive.mjs b/lib/help-archive.mjs index 205c62864..f2a90691d 100644 --- a/lib/help-archive.mjs +++ b/lib/help-archive.mjs @@ -22,8 +22,9 @@ // sizes are in the local header and in the central directory; // - no zip64: more than 65,535 entries, or 4 GB, is refused; // - method 0 (stored) for files that are compressed already, method 8 (raw -// deflate, level 9) for the rest, unless the deflated data is not smaller than -// the file, in which case it is stored. +// deflate) for the rest, unless the deflated data is not smaller than the +// file, in which case it is stored. A file deflated whole is at level 9; one +// deflated in pieces (PIECE_BYTES) is at level 6. // // lib/zip.mjs deflates everything and is shared with other tools, so this // writes its own. @@ -85,6 +86,13 @@ const STORED_EXTENSIONS = new Set([ // A file deflated whole is at most this big; a larger one is deflated in pieces // of this size. The archive's bytes depend on it: changing it changes them. export const PIECE_BYTES = 1 << 20; +// The deflate level of a file deflated whole, and of a piece. A file in pieces is +// a large one, in practice the offline search index (55 MB), the last file the +// build writes: its deflating is on the way to the build's end, and level 6 +// takes under a third of level 9's time for an entry 1.7% larger. The archive's +// bytes depend on both. +const WHOLE_LEVEL = 9; +const PIECE_LEVEL = 6; // What a piece is primed with: deflate's whole window. const WINDOW = 32768; @@ -223,7 +231,7 @@ export function deflateUnit(root, unit) { let method = 0; let body = data; if (!isStoredType(unit.name) && data.length > 0) { - const deflated = deflateRawSync(data, { level: 9 }); + const deflated = deflateRawSync(data, { level: WHOLE_LEVEL }); if (deflated.length < data.length) { if (!inflateRawSync(deflated).equals(data)) { throw new Error(`${unit.name}: the deflated data does not inflate to the file`); @@ -245,7 +253,7 @@ export function deflateUnit(root, unit) { const last = index === count - 1; if (last && fstatSize(file) !== unit.size) throw new Error(`${unit.name} changed size while the archive was made`); const flush = last ? constants.Z_FINISH : constants.Z_SYNC_FLUSH; - const body = deflateRawSync(data, { level: 9, finishFlush: flush, ...(dictionary && { dictionary }) }); + const body = deflateRawSync(data, { level: PIECE_LEVEL, finishFlush: flush, ...(dictionary && { dictionary }) }); const back = inflateRawSync(body, { finishFlush: constants.Z_SYNC_FLUSH, ...(dictionary && { dictionary }), From 952c9da177469c6a1fa9088bda0ab32937befe58 Mon Sep 17 00:00:00 2001 From: Kuba Sunderland-Ober Date: Wed, 18 Nov 2026 14:59:43 +0100 Subject: [PATCH 4/9] docs: the help archive's two deflate levels, and what level 6 gains --- WIP.Build.md | 2 +- docs/Documentation/Tools-Build.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WIP.Build.md b/WIP.Build.md index 3af2de3b1..c128047ab 100644 --- a/WIP.Build.md +++ b/WIP.Build.md @@ -1341,7 +1341,7 @@ and the reader builds it. `test/addin-project.test.mjs` is the gate. ### The help archive -- **The help archive is made by tasks of the build's graph, its deflating on the lanes.** `builder/help-archive-step.mjs` writes `add-in/Resources/HELP/site.zip` from `docs/_site-offline` through `lib/help-archive.mjs`, **before** the Gantt injection. `archivePlan` runs once `flushJoin`, `scss` and `writeOffline` have finished, lists the tree less `LATE_FILES` (`search-index.js`) and deals the deflating into one group of units for each lane (`archiveDeflate:i`), so the tree is deflated while the search index is built. `archiveLate` does the same for `search-index.js` once `searchIndex` has written it (`archiveLateDeflate:i`), and `helpArchive` writes the zip from every group. A unit is a whole file or one 1 MB piece of a larger one; a large file's pieces are one deflate stream, each ending with a sync flush and primed with the 32 KB before it (pigz's method), so the bytes depend only on the piece size. Measured on the 55 MB `search-index.js` at level 9: 3.2 s as one stream, 0.8 s as pieces on four threads, at the same size to within 0.02%. Each unit inflates what it deflated and compares it with the bytes it read; the zip is read back and compared with what was assembled. **The archive leaves out `HELP_ARCHIVE_SKIP`** (`builder/help-archive-step.mjs`): the Documentation Development section (`BuildInfo.html` and `assets/images/gantt.svg` with it, so the chart never reaches the zip), Videos and their poster frames, Challenges, and **every download, which stays online** (owner): a file readers download goes in a `downloads` folder beside its page, and the step fails the build when the Downloads page offers a file the archive would hold. The add-in's server redirects any file the archive lacks to the website, because pages link to all of these; a new entry needs nothing else. A mismatch fails the build (exit 1). After the Gantt injection `recheckHelpArchive` checks that the offline tree on disk lists the same files as the archive and differs from it, in size or CRC-32, only in `BuildInfo.html` and `gantt.svg`; a task that wrote into the offline tree late fails the build there. The help add-in embeds the zip as a resource and serves the pages from it with its own server; a build of the add-in without it uses the live site. The file is gitignored (about 60 MB, 10 MB of it the search index's `search-index.js`, deflated), so a build of the add-in from a clean clone is the online one until `build.bat` has run. The download carries the same zip ([The help add-in's project file](#the-help-add-ins-project-file)). **`--no-help-archive` turns the step off, and neither CI workflow may pass it** (`check_ci_workflows.mjs` refuses it, in `ALLOWED.forbiddenBuildFlags`), because CI's published download would then hold no archive. It runs only for the guarded source tree (`docs`) built into the default `docs/_site-offline` (not another `--dest`, so `compare_trees` and `check_links_diff` leave it alone), never under `--serve` or `--dry-run`, never without an offline tree, and not keyed on `$CI`. There is no command-line tool for the archive: the `help-offline` lane makes its own with `writeHelpArchive`. The zip's format is fixed by the add-in's reader, which does no inflating ([WIP.HelpAddin.md](WIP.HelpAddin.md), Stage 4, increment 5). +- **The help archive is made by tasks of the build's graph, its deflating on the lanes.** `builder/help-archive-step.mjs` writes `add-in/Resources/HELP/site.zip` from `docs/_site-offline` through `lib/help-archive.mjs`, **before** the Gantt injection. `archivePlan` runs once `flushJoin`, `scss` and `writeOffline` have finished, lists the tree less `LATE_FILES` (`search-index.js`) and deals the deflating into one group of units for each lane (`archiveDeflate:i`), so the tree is deflated while the search index is built. `archiveLate` does the same for `search-index.js` once `searchIndex` has written it (`archiveLateDeflate:i`), and `helpArchive` writes the zip from every group. A unit is a whole file or one 1 MB piece of a larger one; a large file's pieces are one deflate stream, each ending with a sync flush and primed with the 32 KB before it (pigz's method), so the bytes depend only on the piece size. Measured on the 55 MB `search-index.js` at level 9: 3.2 s as one stream, 0.8 s as pieces on four threads, at the same size to within 0.02%. **A piece is deflated at level 6, a whole file at level 9** (owner, 2026-11-18): the pieces are `search-index.js`'s, the last file the build writes, so their deflating is on the way to the build's end. Measured on the dev box, three builds each, from the end of `searchIndex` to the start of `helpArchive`: 0.60 to 0.63 s at level 9 and 0.13 to 0.16 s at level 6 on sixteen CPUs, 1.17 to 1.29 s and 0.37 to 0.41 s on four; the whole build 8.6 to 9.4 s and 7.7 to 8.3 s, 15.5 to 17.3 s and 14.5 to 15.0 s. The archive is 206 KB larger (77.66 MB, 77.87 MB). Not measured: CI. Each unit inflates what it deflated and compares it with the bytes it read; the zip is read back and compared with what was assembled. **The archive leaves out `HELP_ARCHIVE_SKIP`** (`builder/help-archive-step.mjs`): the Documentation Development section (`BuildInfo.html` and `assets/images/gantt.svg` with it, so the chart never reaches the zip), Videos and their poster frames, Challenges, and **every download, which stays online** (owner): a file readers download goes in a `downloads` folder beside its page, and the step fails the build when the Downloads page offers a file the archive would hold. The add-in's server redirects any file the archive lacks to the website, because pages link to all of these; a new entry needs nothing else. A mismatch fails the build (exit 1). After the Gantt injection `recheckHelpArchive` checks that the offline tree on disk lists the same files as the archive and differs from it, in size or CRC-32, only in `BuildInfo.html` and `gantt.svg`; a task that wrote into the offline tree late fails the build there. The help add-in embeds the zip as a resource and serves the pages from it with its own server; a build of the add-in without it uses the live site. The file is gitignored (about 60 MB, 10 MB of it the search index's `search-index.js`, deflated), so a build of the add-in from a clean clone is the online one until `build.bat` has run. The download carries the same zip ([The help add-in's project file](#the-help-add-ins-project-file)). **`--no-help-archive` turns the step off, and neither CI workflow may pass it** (`check_ci_workflows.mjs` refuses it, in `ALLOWED.forbiddenBuildFlags`), because CI's published download would then hold no archive. It runs only for the guarded source tree (`docs`) built into the default `docs/_site-offline` (not another `--dest`, so `compare_trees` and `check_links_diff` leave it alone), never under `--serve` or `--dry-run`, never without an offline tree, and not keyed on `$CI`. There is no command-line tool for the archive: the `help-offline` lane makes its own with `writeHelpArchive`. The zip's format is fixed by the add-in's reader, which does no inflating ([WIP.HelpAddin.md](WIP.HelpAddin.md), Stage 4, increment 5). ### Build-time counts as named values diff --git a/docs/Documentation/Tools-Build.md b/docs/Documentation/Tools-Build.md index 9f142c930..dda90513d 100644 --- a/docs/Documentation/Tools-Build.md +++ b/docs/Documentation/Tools-Build.md @@ -126,7 +126,7 @@ The reader on the twinBASIC side does no inflating of its own, so the zip format - The DOS date and time are always 1980-01-01 00:00, and the version made by and needed is 20. - No extra fields, comments or data descriptors: the CRC-32 and both sizes are in the local header and in the central directory. - No zip64, so a tree of more than 65,535 files, or an archive of 4 GB, is refused. -- Files that are compressed already (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.ico`, `.woff2`, `.woff`, `.mp4`, `.zip`, `.pdf`) are stored. Every other file is deflated at level 9, and stored instead when the deflated data is not smaller than the file. +- Files that are compressed already (`.png`, `.jpg`, `.jpeg`, `.gif`, `.webp`, `.ico`, `.woff2`, `.woff`, `.mp4`, `.zip`, `.pdf`) are stored. Every other file is deflated, and stored instead when the deflated data is not smaller than the file. The level is 9 for a file deflated whole and 6 for one deflated in pieces, which is a file larger than 1 MB: the offline search index. - A deflated file larger than 1 MB is deflated in pieces of 1 MB, which are joined into one deflate stream. Every piece but the last ends with a sync flush, and each piece is primed with the 32 KB of the file before it, so the stream is about the size of one made in a single pass. The bytes depend only on the piece size, not on how many pieces were deflated at a time. Each file, or piece, is inflated again after it is deflated and compared with the bytes read. The build then reads the zip back, compares it with what it assembled, and checks every entry's headers against the list of files; it names any that differ. The writer is `lib/help-archive.mjs`. From f4790acf92e4c30f838a070ec0c3b96cf488feae Mon Sep 17 00:00:00 2001 From: Kuba Sunderland-Ober Date: Wed, 18 Nov 2026 15:03:32 +0100 Subject: [PATCH 5/9] WIP.BuildSpeed.md: the rules for work on the build's speed, how to measure it, and the open work --- WIP.BuildSpeed.md | 181 ++++++++++++++++++++++++++++++++++++++++++++++ WIP.md | 1 + 2 files changed, 182 insertions(+) create mode 100644 WIP.BuildSpeed.md diff --git a/WIP.BuildSpeed.md b/WIP.BuildSpeed.md new file mode 100644 index 000000000..17ef9e21e --- /dev/null +++ b/WIP.BuildSpeed.md @@ -0,0 +1,181 @@ +# The build's speed --- Working Notes + +What a session needs before it makes `tbdocs` faster: the rules, how to measure, and the +work that is open. What was done, and why each piece of the pipeline is built as it is, is in +[WIP.Build.md](WIP.Build.md#the-pipeline) and [WIP.Search.md](WIP.Search.md) (*The pre-built +index*), with every measurement that still decides something. History is in git. + +The owner's standard for this work: "Our build's performance was achieved by relentlessly +slicing every 0.1s off until it was perfect. So a 0.1s win is just fine in my book." + +## Rules + +- **Measure before and after, in the same session, more than once.** The dev box is rarely + quiet: one-off builds of one commit range over a second, and a `git` process alone takes + 0.15 to 1.0 s. Compare the base checkout with the branch in alternating runs + (`bench.ps1 -Trees ,`), read each run's chart, and report ranges, never one + total. +- **Measure each kind of build**, because a change that helps one often does nothing for + another: a one-off build on every CPU, a one-off build on four (`start /affinity F`, the + nearest thing to a CI runner), and rebuilds on one pool as `--serve` runs them. Say which + were not measured; CI never is until the owner pushes. +- **Look for a gap before optimising a bar.** The gains so far came mostly from a task + waiting for something it did not need, a lane held by a wait, or the main thread claiming + a long task just before a critical one became ready. Read which task ran in a gap from the + build's timing line: the chart does not draw every main-thread task (`linkJoin`), and a + `submit`'s time is the paler stretch after its bar, not in `=`. +- **A task's time in a build is not its own work while the lanes boot.** Measure a function + alone first, then in the build, and report both. +- **The output must not change unless it is meant to.** `node scripts/compare_trees.mjs` + after every change to `builder/` or `lib/`; then `build.bat`, `check.bat`, `test.bat` and + lint. A rewrite of an inner loop is compared with the old code over every page first (import + both checkouts' modules in one script). +- **No task starts a thread**, and a new lane task or main-thread task needs its entry in + `GANTT_SECTION` (`builder/gantt.mjs`), or the build fails after writing the trees + ([WIP.Build.md](WIP.Build.md#no-task-starts-a-thread)). +- **A task that only waits does not belong on a lane**, and a main-thread task must not + await a process: start it, keep the promise, and await it in the task that needs the answer + ([WIP.Build.md](WIP.Build.md#git-is-started-by-the-main-thread-and-awaited-where-it-is-needed)). +- **Separate commits for code and for docs**, and the developer pages + (`docs/Documentation/Builder.md`, `Pipeline-Stages.md`, `Extending.md`) are updated with the + task graph. + +## How to measure + +The measuring tools are not in the repository yet: they are local, in +`.claude/resume-agents/kit/perf/` of the main checkout (gitignored). Each takes the +repository's Windows path as its first argument unless said. + +| Tool | What it does | +|---|---| +| `bench.ps1 -Trees , -Runs 3 -Out ` | builds each tree on every CPU and on four, prints each "Done in" line, keeps each build's log and `gantt.svg` | +| `serve-gantt.mjs