Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
3cfc7b2
tbdocs: the search index and the help archive run as lane tasks (fanO…
KubaO Nov 17, 2026
553e015
lint: no task of the build starts a thread; builder/ and lib/ import …
KubaO Nov 17, 2026
6eb87e0
docs: the index's and the archive's lane tasks, fanOut, and the rule …
KubaO Nov 17, 2026
b22c69e
tbdocs: packTests runs on a lane and no page waits for it but those t…
KubaO Nov 17, 2026
ef7c69c
docs: packTests on a lane, downloadSizes and the late pages
KubaO Nov 17, 2026
8b3446f
tbdocs: the render lanes do the per-page part of the symbol index and…
KubaO Nov 17, 2026
8dab7a0
docs: packageApi, symbolPlace and searchEntries, the packed search en…
KubaO Nov 17, 2026
4ea793b
tbdocs: the source tree is read in two pieces on the lanes (discoverL…
KubaO Nov 17, 2026
c5e09bd
docs: discoverList and discoverRead:i, the two stages of a lane's boo…
KubaO Nov 17, 2026
8edaff5
tbdocs: the offline_exclude patterns are compiled once for each list …
KubaO Nov 17, 2026
40bd091
docs: fnmatch.mjs and matchesAny, and what is left in dispatch
KubaO Nov 17, 2026
a99a9de
tbdocs: the discoverRead lanes pack their pages' text into a shared b…
KubaO Nov 17, 2026
ff228e1
docs: packPageText and pageText, the render chunks' payloads, and wha…
KubaO Nov 17, 2026
d1f4466
tbdocs: findCountRefs cuts into code spans only the lines that hold a…
KubaO Nov 17, 2026
a18bec2
docs: what markdownInit is made of, and findCountRefs
KubaO Nov 17, 2026
9b0523c
tbdocs: computeNav sorts each page's children once for the tree, the …
KubaO Nov 17, 2026
67b93ea
tbdocs: dispatch does not wait for buildInfo, which only the book's t…
KubaO Nov 17, 2026
16d9ed4
docs: buildInfo and bookPayload, the pieces of the source tree by CPU…
KubaO Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/run-gates/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ runs:
- name: Unit-test the IDE's main.js tool (test/ide-js.test.mjs)
shell: bash
run: node --test test/ide-js.test.mjs
# Unit tests for builder/discover.mjs and discover-read.mjs: the source
# tree's inventory, which the build reads in pieces on its lanes. They read
# a small tree of their own in any number of pieces, with a picture pair
# that has a file from outside the tree. No build, no lanes.
- name: Unit-test the source tree's inventory (test/discover.test.mjs)
shell: bash
run: node --test test/discover.test.mjs
# A regex that backtracks exponentially does not fail a build, it stops
# one: the corpus passes until a page happens to contain the trigger, and
# then a render worker sits inside String.replace forever. Nothing else
Expand Down
248 changes: 232 additions & 16 deletions WIP.Build.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WIP.HelpAddin.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ The table gives each answer in brief; the sections above have the detail.

### Stage 3: the symbol index, generated by the docs build

The index is the `symbolIndex` task of the build, in [builder/symbols.mjs](builder/symbols.mjs),
The index is made by the `symbolPlace` task of the build and written by `symbolIndex`, in [builder/symbols.mjs](builder/symbols.mjs),
and it publishes [`/tB/symbols.json`](docs/Documentation/Permanent-Links.md#the-symbol-index) ---
under `/tB/` because the file is part of the same contract as the URLs in it, and its URL is
fixed from here on. Permanent Links documents the format for any reader;
Expand Down
110 changes: 81 additions & 29 deletions WIP.Search.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,11 @@ single boost:
have a container -- a bare statement or operator does not), space-separated
and deduplicated. Boost 500 (see "Qualified names and stem twins").

- In the build, `searchData` also waits for `symbolIndex`. Both run on the
main thread after `renderJoin`. `symbolIndex` returns its symbols, and
`searchData` joins them by URL before it writes (`joinSymbolsToEntries` in
`search.mjs`). Workers derive sections; the join is a map lookup per entry.
- In the build, `searchEntries` waits for `symbolPlace`. Both run on the
main thread after `renderJoin`. `symbolPlace` returns its symbols, and
`searchEntries` joins them by URL (`joinSymbolsToEntries` in `search.mjs`).
Workers derive sections; the join is a map lookup per entry. `searchData`
writes the file afterwards.
- `renderEntryString` adds `names` / `qualified` only when non-empty, so a
page with no symbols produces the same bytes as without the join.

Expand Down Expand Up @@ -564,35 +565,86 @@ gzipped). With the one file, the page shows results 0.86 to 0.99 s after
the keystroke, the typing and the drawing included, as with two; offline,
2.1 to 2.2 s (1.6 s with two scripts, the entries then an object literal).

**The build makes it on threads** (`builder/search-index.mjs`,
`search-index-worker.mjs`). On one thread lunr takes 3.6 to 4.8 s: `add()`
76% of it, the field vectors 13%, the token set 6% (never needed here: it is
not in the JSON, and `Index.load` makes it), the average lengths and the
fields' preparation the rest. lunr cannot merge two indexes, but `add()` is
independent per entry, so each thread adds a contiguous run of the entries;
the build merges their postings, numbers every term in the order a single
build first meets it (a thread's terms in its own order, the threads in
**The build makes it in slices, on its lanes** (`builder/search-index.mjs`;
the tasks `indexSlices`, `indexAdd:i`, `indexMerge`, `indexTerms`,
`indexVectors:i` and `searchIndex` in `tbdocs.mjs`). On one thread lunr takes
3.6 to 4.8 s: `add()` 76% of it, the field vectors 13%, the token set 6%
(never needed here: it is not in the JSON, and `Index.load` makes it), the
average lengths and the fields' preparation the rest. lunr cannot merge two
indexes, but `add()` is independent per entry, so each slice, a contiguous
run of the entries, is added to a builder of its own on a lane;
`indexMerge` merges their postings, numbers every term in the order a single
build first meets it (a slice's terms in its own order, the slices in
entry order; never in key order, which puts number-like terms first), sums
each term's document count and each field's length, computes `lunr.idf` and
the averages (the `index` field's pinned at 1), and has each thread make its
the averages (the `index` field's pinned at 1), and each slice's lane makes its
entries' vectors with lunr's own `createFieldVectors`, `lunr.idf` answering
from those totals. The JSON is written as `toJSON` writes it. The result is
byte for byte `JSON.stringify(lunr(config))` for any number of threads, on
the site (checked at 1, 3 and 8 threads) and on `test/search-index.test.mjs`'s
fixture, which fails when the pinned average or the term order is broken.
On 16 threads: 4.8 s on one, 2.8 on two, 1.9 on four, 1.6 on six, 1.4 on
eight; the build uses half the machine, at most eight, and one for every 500
entries.

**What it costs the build.** The `searchIndex` task runs on a lane, reading
`search-data.json` from disk: as a main-thread task it would hold back
`bookPayload`, `writeAux` and `writeOffline` (the main thread runs one task
at a time), at a cost of 1.9 s. On a lane it takes about 2.3 s after
`searchData`, and it is the last task of a build without the help
archive (about 1.7 s more in `compare_trees`, 7.9 s); with the archive,
`helpArchive` waits for it. The index adds about 8.4 MB to the help archive
and to the add-in's project download (owner: fine, for now). The build time
is the price of the index (owner).
byte for byte `JSON.stringify(lunr(config))` for any number of slices, on
the site (`compare_trees` against the build that made it on threads of its
own) and on `test/search-index.test.mjs`'s fixture, which fails when the
pinned average or the term order is broken.

**It was once made on threads the task started itself**, half the machine's
and at most eight, which the Gantt chart did not show and which left the lanes
idle beside them; no task starts a thread now (WIP.Build.md, "No task starts a
thread"). The slices are of about equal text, not of equal entries, since
adding an entry costs about what its text is long: of eight slices the
longest then takes 0.71 s and the shortest 0.54 s. There are two for each
lane, so that a lane which finishes early takes another while a lane busy
with the PDF tree catches up, and one for every 500 entries at most. The
total does not grow with the slices: 6.1 s of CPU as one slice, 4.5 to 5.2 s
as 2 to 32, on the dev box.

**Adding the entries during render was considered and not done** (owner asked,
2026-11-17). An entry has its final form only once every page is rendered:
its number depends on every entry before it and on the term entries
`settleLabels` drops, its `names`, `qualified` and `primary` come from the
symbol index, `qualified` needs the stem twins of all entries, and its index
terms and the words appended to its content come from `settleLabels` too. The
fields known at render time (title, content, page, URL) could be indexed then
under provisional numbers, in a builder of their own, and patched afterwards.
It would not shorten a build on a 4-core runner: every lane is busy for the
whole of render, so the index's CPU would lengthen render by what it took off
the tail. The only idle time it could use is the ragged end of render, up to
0.3 s on some of 16 lanes, and one slice for each of the render chunks would be
about five times the builders.

**What the lanes wait for after the last render chunk** is three main-thread
tasks, `symbolPlace`, `searchEntries` and `indexSlices`, with every lane idle,
so they do only what needs every page (`tbdocs.mjs`, "From the last render
chunk to the search index's slices"). The rule for anything added there: what
one page or one entry decides is done by the lane that renders it, what is
known from the start is read during render, and what only writes a file comes
after `indexSlices`. So the render lanes read the headings of the pages the
symbol index reads, work out each entry's settle keys (`entryKeys`: the
normalising was most of `settleLabels`), and pack each chunk's entries as the
head and tail of their text in `search-data.json` into a SharedArrayBuffer
(`packSearchEntries`). The index's lanes read their entries from those
buffers, and a slice's payload holds only where its entries are and the fields
decided since (`planIndexSegments`); `searchData` copies the same bytes into
the file around each entry's number and late fields. Before, the entries went
to the lanes a second time, as JSON the main thread wrote from a parse of the
file it had just written.

Measured on the dev box (16 threads), from the end of the last render chunk
to the end of `indexSlices`: 0.25 to 0.32 s before and 0.09 to 0.15 s after
in a full build, 0.37 to 0.38 s and 0.15 to 0.25 s on 4 CPUs, 0.26 to 0.31 s
and 0.08 to 0.12 s in a serve rebuild. What is left, by a CPU profile of the
main thread: `deriveSymbolIndex` about 45 ms, `settleLabels` and the join about
35 ms, the stem twins about 20 ms, the plan and its payload about 20 ms. Not
done: making `deriveSymbolIndex` faster (`placeOwnPages` goes through every
page of a folder for every type), and the stem twins on a lane while the main
thread settles the entries (they need only the symbols and which URLs an entry
matched). An entry's settle keys go beside the entries, not on them:
`delete` of a property on each of 13,500 entries took 11 ms.

**What it costs the build.** About 5 s of CPU, spread over the lanes after
`indexSlices`, and about 0.6 s on the main thread for `indexMerge`,
`indexTerms` and the writing. `archiveLate` waits for it, and deflates
`search-index.js` for the help archive in pieces on the lanes. The index adds
about 8.4 MB to the help archive and to the add-in's project download (owner:
fine, for now). The build time is the price of the index (owner).

## Step numbers in code comments

Expand Down
2 changes: 2 additions & 0 deletions WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ The site builds via [builder/](builder/), a custom Node.js static site generator

The task-graph scheduler and parallelisation are described in [builder/PLAN-scheduler.md](builder/PLAN-scheduler.md). A task that never finishes fails the build after `--stall-timeout` seconds ([WIP.Build.md](WIP.Build.md#a-hung-build-times-out-and-says-where-it-hung)).

**No task of the build starts a thread** (owner): the lanes are its only threads. Work that should run in parallel is split into lane tasks with `fanOut` (`builder/fan-out.mjs`), so that the scheduler places it and the Gantt chart shows it. A task starts no worker thread and no process for its work, and puts no CPU work on Node's thread pool, which zlib's functions without `Sync` in their name do. `check_lint.mjs` refuses the imports; the reasons and the exceptions are in [WIP.Build.md](WIP.Build.md#no-task-starts-a-thread).

### Compiling the reference's own code samples

No build gate evaluates a `tb` fence: `check_code_regions.mjs` only protects its
Expand Down
120 changes: 118 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@
// exception is scripts/impexp.mjs, which builder/addin-project.mjs packs
// the help add-in's project file with: it imports nothing, the build
// already publishes it, and check_tree_fresh.mjs watches it by name.
//
// `paths` is the other rule here: no task of the build starts a thread
// (WIP.Build.md, "No task starts a thread"). The lanes are the build's
// threads, and work that should run in parallel is split into lane
// tasks (builder/fan-out.mjs), so that the scheduler places it and the
// Gantt chart shows it. So nothing in builder/ may import
// worker_threads or cluster, start a process, or put CPU work on
// Node's thread pool, which is what zlib's functions do unless their
// name ends in Sync. The overrides after this one name the files that
// may: each repeats `patterns`, since an override replaces the rule's
// options whole.
"includes": ["builder/**/*.mjs"],
"linter": {
"rules": {
Expand All @@ -114,7 +125,86 @@
"group": ["**/scripts/**", "!**/scripts/impexp.mjs"],
"message": "builder/ must not depend on scripts/."
}
]
],
"paths": {
"node:worker_threads": "No task starts a thread: split the work into lane tasks (builder/fan-out.mjs). Only worker-pool.mjs and cpu-worker.mjs import worker_threads.",
"worker_threads": "No task starts a thread: split the work into lane tasks (builder/fan-out.mjs). Only worker-pool.mjs and cpu-worker.mjs import worker_threads.",
"node:cluster": "No task starts a process: split the work into lane tasks (builder/fan-out.mjs).",
"cluster": "No task starts a process: split the work into lane tasks (builder/fan-out.mjs).",
"node:child_process": "No task starts a process for its work: split it into lane tasks (builder/fan-out.mjs). Only build-info.mjs and addin-project.mjs run a program, git.",
"child_process": "No task starts a process for its work: split it into lane tasks (builder/fan-out.mjs). Only build-info.mjs and addin-project.mjs run a program, git.",
"node:zlib": {
"allowImportNames": [
"constants",
"crc32",
"deflateSync",
"deflateRawSync",
"inflateSync",
"inflateRawSync",
"gzipSync",
"gunzipSync",
"unzipSync",
"brotliCompressSync",
"brotliDecompressSync"
],
"message": "Import zlib's Sync functions by name: the others run on Node's thread pool, outside the lanes. Split CPU work into lane tasks (builder/fan-out.mjs)."
},
"zlib": "Import from node:zlib, by name."
}
}
}
}
}
}
},
{
// The two modules that are the lanes: the pool that starts them, and
// the harness each one runs.
"includes": ["builder/worker-pool.mjs", "builder/cpu-worker.mjs"],
"linter": {
"rules": {
"style": {
"noRestrictedImports": {
"level": "error",
"options": {
"patterns": [
{
"group": ["**/scripts/**", "!**/scripts/impexp.mjs"],
"message": "builder/ must not depend on scripts/."
}
],
"paths": {
"node:cluster": "No task starts a process: split the work into lane tasks (builder/fan-out.mjs).",
"node:child_process": "No task starts a process for its work: split it into lane tasks (builder/fan-out.mjs).",
"node:zlib": "The lanes' own modules deflate nothing: import the module that does."
}
}
}
}
}
}
},
{
// The two modules that run a program: git, for the build's commit and
// for the files the add-in's project file packs.
"includes": ["builder/build-info.mjs", "builder/addin-project.mjs"],
"linter": {
"rules": {
"style": {
"noRestrictedImports": {
"level": "error",
"options": {
"patterns": [
{
"group": ["**/scripts/**", "!**/scripts/impexp.mjs"],
"message": "builder/ must not depend on scripts/."
}
],
"paths": {
"node:worker_threads": "No task starts a thread: split the work into lane tasks (builder/fan-out.mjs).",
"node:cluster": "No task starts a process: split the work into lane tasks (builder/fan-out.mjs).",
"node:zlib": "These modules deflate nothing: import the module that does."
}
}
}
}
Expand All @@ -125,6 +215,11 @@
// lib/ holds modules every other part of the tooling may import
// (lib/README.md), so it imports none of them; a lib/ module that reached
// into scripts/ would take builder/ there with it.
//
// The build imports lib/, so the thread rule above holds here for what
// lib/ uses today: no thread of its own, and zlib's Sync functions by
// name. A tool outside the build that needs a thread starts it in its
// own module, not in lib/.
"includes": ["lib/**/*.mjs"],
"linter": {
"rules": {
Expand All @@ -145,7 +240,28 @@
],
"message": "lib/ must not import builder/, scripts/, book/, eval/, wisdom/, indexer/ or test/."
}
]
],
"paths": {
"node:worker_threads": "lib/ starts no thread: the build imports it, and no task of the build starts a thread (WIP.Build.md).",
"worker_threads": "lib/ starts no thread: the build imports it, and no task of the build starts a thread (WIP.Build.md).",
"node:zlib": {
"allowImportNames": [
"constants",
"crc32",
"deflateSync",
"deflateRawSync",
"inflateSync",
"inflateRawSync",
"gzipSync",
"gunzipSync",
"unzipSync",
"brotliCompressSync",
"brotliDecompressSync"
],
"message": "Import zlib's Sync functions by name: the others run on Node's thread pool, outside the build's lanes (WIP.Build.md, \"No task starts a thread\")."
},
"zlib": "Import from node:zlib, by name."
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ render-worker sub-stage.

| Phase | Module(s) | Job |
|---|---|---|
| 1 | [discover.mjs](discover.mjs) + [publish-policy.mjs](publish-policy.mjs) | Read .md/.html + frontmatter, enumerate static files, refuse any that is not a publishable type |
| 1 | [discover.mjs](discover.mjs) + [discover-read.mjs](discover-read.mjs) + [publish-policy.mjs](publish-policy.mjs) | List the source tree; on two lanes, read .md/.html + frontmatter and size the static files; refuse any that is not a publishable type |
| 2 | [nav.mjs](nav.mjs) / [seo.mjs](seo.mjs) / [book.mjs](book.mjs) / [build-info.mjs](build-info.mjs) / [data.mjs](data.mjs) | Compute nav tree, SEO, book chapters, git commit info, `_data/*.yml` |
| 3 | [render.mjs](render.mjs) + [highlight.mjs](highlight.mjs) + [highlight-theme.mjs](highlight-theme.mjs) | Markdown -> HTML body |
| 4 | [template.mjs](template.mjs) + [compress.mjs](compress.mjs) | Wrap in layout, anchor-heading injection, whitespace compress |
Expand Down
Loading
Loading