← Back to Pull requests

perf: let metadata and section-pages start on their dependency's first chunk #1240

Closed
unknown closed this pull request without merging on Nov 18, 2026 03:37 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 19:34 UTC
Author

<!--
Please read the Code of Conduct and the Contributing Guidelines before opening a pull request.
-->

Description

This PR lets metadata and section-pages start 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-pages passes 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.

  • Each of metadata's chunks holds whole modules, so section-pages reads its input as it comes, with no regrouping. creating-generators.md now states that guarantee.

  • A generator that sets streamsInput now 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 one for await either way.
  • Why it's built this way

    Why does this barely move the site build? The overlap here is between ast, metadata and section-pages, and stops there. -t section-pages is delivered through html and sitemap, so the site build also runs jsx-ast, html and sitemap. But jsx-ast, which reads section-pages, still takes its input whole, and so do json, orama-db and llms-txt, which read metadata. jsx-ast and html stream in #1241, which is where the site build gets its -17% (4 threads) and -20% (6 threads) against main. 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 overlapping ast and metadata does save time.

    The in-flight limit doesn't stop this. threads * CHUNKS_PER_THREAD is counted per worker.stream call, so at 4 threads ast and metadata can 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 and worker.stream runs 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 had groupWholeModules, because I assumed a chunk could end partway through a module. It can't. parseApiDoc sets api once per file, from the file's path, and worker.stream splits 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 because jsx-ast relies 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 sitemap lists depth-1 entries in input order. Yielding each batch's chunk pages right away would mix them in with the module pages and reorder sitemap.xml. It costs nothing next to main, which also built every chunk page after the whole input and returned everything at the end. From #1241 on, html puts its pages in site order itself. So if we want the chunk pages to go out earlier, the cheaper fix is a sort in sitemap. 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 toBatches helper to accept both. Core now wraps the collected array as a single chunk, so toBatches and the array-or-iterable types go, here and in jsx-ast, html and html-all later 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 1 is the build that has to fit in 512MB. streamsInput isn'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, for runGenerators giving a streaming generator its whole input as one chunk with one thread, and for section-pages building 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 to main's.

    Related Issues

    Refs: #1205

    Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.

  • I have run node --run test and all tests passed.

  • I have check code formatting with node --run format:check & node --run lint.

  • I've covered new added functionality with unit tests if necessary.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: avivkeller Review duration: 20643m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository