← Back to Pull requests

perf: keep none of the CLI's target output #1239

Closed
unknown closed this pull request without merging on Nov 13, 2026 16:48 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 runGenerators keep none of the requested generators' output. It's the third part of a stack that splits #1205.

generate and preview collected every target's output into the arrays runGenerators returns, though neither reads them. With discardResults: true in the configuration it drains them instead: each generator still runs to its end, and once nothing else reads its output, its chunks go as they're produced. Both commands now set it, and docs/configuration.md lists it next to threads and chunkSize.

Why it's built this way

Why keep nothing? The targets write their own files, but collecting still costs memory: consume gathers a streamed target into one array, and every target's result sits in the returned array until the last target ends. In the site build that's json's 70 documents (15 MB as written files), plus orama-db's database, llms-txt's text and section-pages' entries. The payoff grows in later layers: from #1240 on, section-pages streams and yields every metadata entry, which consume would hold until the run ends. It's off by default, so other callers get the same arrays as before.

Why does drain await ended instead of reading the chunks? Since #1238 the tee runs its generator to the end by itself, whether anyone reads it or not. So drain only has to count as one read and wait, and it never holds a chunk. Once release calls forget() and no other reader is left, nothing references a chunk after it's produced, and a failure still reaches runGenerators because ended rejects with it. On share() (15ca206) the generator only moved when a reader pulled it, so drain had to pull every chunk itself. share() also kept every chunk it handed out until its last reader ended, so drain read the raw generator when it was the only read, and kept them all whenever another generator read the same target. On the real cache, one reader over 40 chunks of 4 MB peaked at 1 chunk (4 MB) live with the tee and 40 chunks (153 MB) with share().

Why is teeOf called before release? When drain is the last read, release forgets the tee and deletes it, so calling teeOf first means the tee that gets forgotten is the one already running. In the other order, teeOf would start a second tee after eviction. If nothing else read the target, nothing would ever forget it and it would keep every chunk; if others were already reading, the two tees would split the generator's chunks between them.

Benchmarks

Full Node.js docs on Node 26, compared with #1238 (the layer below). Medians of 5 interleaved runs (4 at 6 threads), peak is RSS summed over the process tree. Site is -t orama-db -t json -t llms-txt -t section-pages, legacy is -t legacy-html-all -t legacy-json-all.

| Build | Threads | #1238 | This PR | Time | Memory |
| --- | --- | --- | --- | --- | --- |
| site | 4 | 9.26 s, 1749 MB | 9.37 s, 1686 MB | +1% | -4% |
| site | 6 | 8.39 s, 2304 MB | 8.27 s, 2306 MB | -1% | +0% |
| legacy | 4 | 4.40 s, 1578 MB | 4.37 s, 1531 MB | -1% | -3% |
| legacy | 6 | 4.21 s, 2033 MB | 4.14 s, 1980 MB | -2% | -3% |

On its own this PR is flat, and the time changes are noise. Legacy's -3% is mostly #1238 measuring high (+3% and +4% against main; this PR is +0% and +1%), and its per-run peaks overlap. The site build's -4% at 4 threads fits the results no longer being kept, but the per-run peaks barely separate (1682-1729 MB against 1728-1772 MB), and at 6 threads they overlap fully.

Validation

Added tests for draining a result alongside its other readers, a non-streaming result and a generator that fails, for the chunks of a drained result being let go as they are produced, and for runGenerators returning no results with discardResults, and rejecting with a dependency's failure, leaving none unhandled, with or without it. 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: 579 lines (+434 / -145) across 7 files Reviewer: avivkeller Review duration: 14234m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 579 lines diff across 7 files
    0.50
    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.381
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1239"
    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: 49.9% (MEDIUM) · Higher = larger blast radius
    49.9%
    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: 19.7% · Safe to merge
    19.7%
    Repository