perf: let metadata and section-pages start on their dependency's first chunk #1240
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1240"
general
weight: 0.35
avivkeller
<!--
Please read the Code of Conduct and the Contributing Guidelines before opening a pull request.
-->
Description
This PR lets
metadataandsection-pagesstart on their dependency's first chunk instead of waiting for all of it, so with more than one thread parsing, metadata and section pages overlap. It's the fourth part of a stack that splits #1205.section-pagespasses each batch of entries on as it arrives and builds that batch's chunk pages, which it adds after the last batch, in module order, as if built from the whole input at once.metadata's chunks holds whole modules, sosection-pagesreads its input as it comes, with no regrouping.creating-generators.mdnow states that guarantee.streamsInputnow always gets an async iterable. With one thread its input is still collected first, but arrives as its only chunk instead of as the array, so the generator reads it with onefor awaiteither way.Why it's built this way
Why does this barely move the site build? The overlap here is between
ast,metadataandsection-pages, and stops there.-t section-pagesis delivered throughhtmlandsitemap, so the site build also runsjsx-ast,htmlandsitemap. Butjsx-ast, which readssection-pages, still takes its input whole, and so dojson,orama-dbandllms-txt, which readmetadata.jsx-astandhtmlstream in #1241, which is where the site build gets its -17% (4 threads) and -20% (6 threads) againstmain. So this layer is mostly a precondition. On its own it saves 0.14 to 0.36s. In the site build that's within run-to-run spread. In the legacy build it isn't: at both thread counts, every run on this branch beat every run on #1239. So overlappingastandmetadatadoes save time.The in-flight limit doesn't stop this.
threads * CHUNKS_PER_THREADis counted perworker.streamcall, so at 4 threadsastandmetadatacan each have up to 12 chunks in the pool at once. A benchmark like #1253 can't see this PR. With one thread, core hands every generator its input whole andworker.streamruns each chunk on the main thread, so nothing overlaps. It also builds no section pages.Why no regrouping of
metadata's chunks? The first version hadgroupWholeModules, because I assumed a chunk could end partway through a module. It can't.parseApiDocsetsapionce per file, from the file's path, andworker.streamsplits a batch by item, so each chunk holds whole files, which means whole modules. Aviv pointed this out. Dropping it removed the helper (61 lines) and its 92 lines of tests, and made no measurable difference to #1241 at 6 threads over 7 runs. The guarantee is documented becausejsx-astrelies on it in #1241 too.Why hold the chunk pages until the end? Only to keep the output identical. Each chunk page's first entry is promoted to depth 1, and
sitemaplists depth-1 entries in input order. Yielding each batch's chunk pages right away would mix them in with the module pages and reordersitemap.xml. It costs nothing next tomain, which also built every chunk page after the whole input and returned everything at the end. From #1241 on,htmlputs its pages in site order itself. So if we want the chunk pages to go out earlier, the cheaper fix is a sort insitemap. I'd rather do that in its own PR.Why always an async iterable, and still collected with one thread? Aviv's idea: until now a streaming generator got the collected array with one thread and an iterable with more, so each one went through a
toBatcheshelper to accept both. Core now wraps the collected array as a single chunk, sotoBatchesand the array-or-iterable types go, here and injsx-ast,htmlandhtml-alllater in the stack. With one thread the input is still collected first, as before: streaming there would only interleave the stages and keep each stage's data alive at the same time, and-p 1is the build that has to fit in 512MB.streamsInputisn't released yet (it's in #1238's pending changeset), so nobody outside depends on the array. On the full Node.js docs at-p 1, the whole stack with and without this change builds the site in 21.99s and 21.98s (medians of 5), with peaks of 1945MB and 1927MB, within the spread of the runs.Benchmarks
Full Node.js docs on Node 26. Each number is the median of 5 interleaved runs (4 for #1239 at 6 threads, and for
main's legacy build at 6 threads). Peak is RSS summed over the process tree. Site is-t orama-db -t json -t llms-txt -t section-pages, and legacy is-t legacy-html-all -t legacy-json-all.| Build | Threads | #1239 | This PR | vs #1239 | vs
main|| --- | --- | --- | --- | --- | --- |
| site | 4 | 9.37s, 1686MB | 9.02s, 1707MB | -4% time, +1% mem | -3%, -2% |
| site | 6 | 8.27s, 2306MB | 8.08s, 2240MB | -2%, -3% | -2%, -5% |
| legacy | 4 | 4.37s, 1531MB | 4.23s, 1533MB | -3%, +0% | -4%, +0% |
| legacy | 6 | 4.14s, 1980MB | 3.96s, 1928MB | -4%, -3% | -6%, -1% |
Memory is flat. The site build's -3% at 6 threads is within #1239's spread there (2189 to 2399MB over 4 runs).
Validation
Added tests for
once, forrunGeneratorsgiving a streaming generator its whole input as one chunk with one thread, and forsection-pagesbuilding the same output from several batches as from its whole input, as it gets it with one thread, and passing each batch on before the next one arrives. Built on 12 of Node.js's API docs at 1 and 4 threads, the output is byte-identical tomain's.Related Issues
Refs: #1205
Check List
node --run testand all tests passed.node --run format:check&node --run lint.