Skip to content

stream: limit iter from sync iterable batches#63324

Open
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:stream-iter-from-iterable-batching
Open

stream: limit iter from sync iterable batches#63324
trivikr wants to merge 2 commits into
nodejs:mainfrom
trivikr:stream-iter-from-iterable-batching

Conversation

@trivikr
Copy link
Copy Markdown
Member

@trivikr trivikr commented May 15, 2026

Description

This updates stream/iter normalization to use bounded batches for sync
iterable input.

from() no longer batches sync iterables into one unbounded batch. Instead, it
flushes at FROM_BATCH_SIZE, improving first-batch latency and bounding peak
batch memory. fromSync() now also coalesces plain Uint8Array values from
sync iterables into bounded batches, allowing pipeToSync() to use writevSync
for those sources.

Benchmarks

Results showed statistically significant first-batch latency improvements for
from(syncIterable):

  • +3.19% for 256 chunks
  • +5.01% for 4096 chunks
  • +2.80% for 16384 chunks

The benchmark also showed a +6.91% writevSync improvement for the 256 chunk
case. The 4096 chunk writev result was not statistically significant.

                                                                                         confidence improvement accuracy (*)   (**)  (***)
streams/iter-from-batching.js n=100 chunkSize=16 chunks=256 method='from-sync-writev'           ***      6.91 %       ±1.99% ±2.65% ±3.46%
streams/iter-from-batching.js n=100 chunkSize=16 chunks=4096 method='from-sync-writev'                  -2.63 %       ±3.60% ±4.84% ±6.41%
streams/iter-from-batching.js n=1000 chunkSize=16 chunks=16384 method='from-first-batch'        ***      2.80 %       ±1.39% ±1.86% ±2.44%
streams/iter-from-batching.js n=1000 chunkSize=16 chunks=256 method='from-first-batch'          ***      3.19 %       ±1.27% ±1.68% ±2.19%
streams/iter-from-batching.js n=1000 chunkSize=16 chunks=4096 method='from-first-batch'         ***      5.01 %       ±2.60% ±3.48% ±4.59%

Assisted-by: openai:gpt-5.5

trivikr added 2 commits May 14, 2026 23:11
Bound sync iterable normalization in from() and fromSync() to
FROM_BATCH_SIZE. This avoids unbounded batches for from() sync
iterable fallbacks and lets fromSync() coalesce plain Uint8Array
values for writev paths.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance
  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels May 15, 2026
@trivikr trivikr self-assigned this May 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 57.89474% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.02%. Comparing base (2edd842) to head (d08b083).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/streams/iter/from.js 57.89% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63324      +/-   ##
==========================================
- Coverage   90.04%   90.02%   -0.03%     
==========================================
  Files         714      714              
  Lines      225338   225377      +39     
  Branches    42598    42610      +12     
==========================================
- Hits       202897   202886      -11     
- Misses      14236    14267      +31     
- Partials     8205     8224      +19     
Files with missing lines Coverage Δ
lib/internal/streams/iter/from.js 86.05% <57.89%> (-2.77%) ⬇️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@trivikr trivikr added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels May 15, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 15, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants