Skip to content

Conversation

@ronag
Copy link
Member

@ronag ronag commented Oct 27, 2025

Instead of wasting cycles concatenating buffers, just return each one by one.

@ronag ronag requested a review from mcollina October 27, 2025 18:44
@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Oct 27, 2025

Review requested:

  • @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 Oct 27, 2025
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

I think some docs changes are needed

@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jan 2, 2026
@mcollina
Copy link
Member

mcollina commented Jan 2, 2026

Marked as semver-major.

@lpinca
Copy link
Member

lpinca commented Jan 2, 2026

I'm -1 on this unless there is a strong reason for it. Historically, readable.read() has always returned all queued data. If this lands, I think that the easiest workaround for modules affected by the breaking change would be replacing readable.read() with readable.read(readable.readableLength).

@ronag
Copy link
Member Author

ronag commented Jan 2, 2026

I'm -1 on this unless there is a strong reason for it.

The performance overhead is huge. As it stand we should at least add a note to avoid this api for anything performance sensitive.

If this lands, I think that the easiest workaround for modules affected by the breaking change would be replacing readable.read() with readable.read(readable.readableLength).

Good point.

@ronag
Copy link
Member Author

ronag commented Jan 2, 2026

I think some docs changes are needed

What doc changes are you roughly asking for?

@ronag ronag force-pushed the read-no-copy branch 2 times, most recently from a380c35 to 0798db8 Compare January 2, 2026 08:55
ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
@ronag ronag marked this pull request as ready for review January 2, 2026 08:56
@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 2, 2026
ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jan 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - stream: readable read one buffer at a time
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/20654449594

@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Jan 2, 2026
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jan 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - stream: readable read one buffer at a time
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/20654684497

@mcollina
Copy link
Member

mcollina commented Jan 2, 2026

actually, no doc changes are needed.

Each call to readable.read() returns a chunk of data or null, signifying that there's no more data to read at that moment. These chunks aren't automatically concatenated. Because a single read() call does not return all the data, using a while loop may be necessary to continuously read chunks until all data is retrieved. When reading a large file, .read() might return null temporarily, indicating that it has consumed all buffered content but there may be more data yet to be buffered. In such cases, a new 'readable' event is emitted once there's more data in the buffer, and the 'end' event signifies the end of data transmission.

@lpinca this PR matches what we are already documenting. We could even make a case for this to be a bugfix.

Anyway, we should run citgm and see if there are breakages.

Given the significant impact on performance, I think we should be landing this.

@ronag ronag force-pushed the read-no-copy branch 4 times, most recently from 7053647 to bb6af6c Compare January 2, 2026 09:47
@lpinca
Copy link
Member

lpinca commented Jan 2, 2026

Anyway, we should run citgm and see if there are breakages.

There is an occurrence in ws and I don't think CITGM would catch it because, if I remember correctly, the test uses a single buffer, but I can probably fix it as written above.

ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
ronag added a commit to ronag/node that referenced this pull request Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
@ronag ronag requested review from lpinca and mcollina January 2, 2026 10:10
@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. needs-citgm PRs that need a CITGM CI run. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Jan 2, 2026
Instead of wasting cycles concatenating buffers, just return each
one by one.

Old behavior can be achieved by using `readable.read(readable.readableLength)` instead of `readable.read()`.

PR: nodejs#60441
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jan 2, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2026

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - stream: readable read one buffer at a time
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/20655680849

@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels Jan 2, 2026
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 2, 2026
@nodejs-github-bot
Copy link
Collaborator

@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.55%. Comparing base (0457bfe) to head (93274c5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #60441      +/-   ##
==========================================
+ Coverage   88.53%   88.55%   +0.01%     
==========================================
  Files         704      704              
  Lines      208736   208741       +5     
  Branches    40274    40276       +2     
==========================================
+ Hits       184810   184856      +46     
+ Misses      15944    15905      -39     
+ Partials     7982     7980       -2     
Files with missing lines Coverage Δ
lib/internal/streams/readable.js 96.27% <100.00%> (+0.01%) ⬆️

... and 33 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.

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

Labels

needs-ci PRs that need a full CI run. needs-citgm PRs that need a CITGM CI run. semver-major PRs that contain breaking changes and should be released in the next major version. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants