← Back to Pull requests

perf: let worker.stream take chunks as they arrive #1237

Closed
unknown closed this pull request without merging on Nov 09, 2026 02:26 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 worker.stream take an async iterable of batches as well as an array, starting a batch's work while earlier ones still run. It's the first part of a stack that splits #1205, which lets generators start on their dependency's first chunk instead of waiting for all of it.

  • With more than one thread it keeps only a few chunks per thread in flight (CHUNKS_PER_THREAD, 3), whether its input is an array or streamed, so generators running at once share the worker pool instead of one filling it. It reads the next batch once there's room for its chunks, and yields results in the order the chunks were submitted.

  • Piscina runs with stricterFIFO. By default it puts a task it can't hand out yet at the back of its queue, so early heavy tasks like module pages ran last.

  • One enqueue starts a batch's chunks, waiting while the limit is reached, and the consumer waits on an inline Promise.withResolvers() as chunks start. An array is read as [items], so its first chunks start right away.
  • Nothing passes worker.stream a stream yet. With one thread nothing changes, and with more, an array's chunks now start a few per thread at a time instead of all at once, with the same output.

    Validation

    Added tests in parallel.test.mjs for the streamed input: the limit on chunks in flight and its refill, the order tasks start in, a failure reading the batches arriving after the chunks before it, a single thread running each batch as it arrives, and no batches. 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: 282 lines (+211 / -71) across 3 files Reviewer: avivkeller Review duration: 7612m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 282 lines diff across 3 files
    0.40
    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.338
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1237"
    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: 39.7% (MEDIUM) · Higher = larger blast radius
    39.7%
    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: 15.7% · Safe to merge
    15.7%
    Repository