Skip to content

stream: improve Readable#from perf - #50359

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
rluvaton:improve-from
Oct 26, 2023
Merged

stream: improve Readable#from perf#50359
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
rluvaton:improve-from

Conversation

@rluvaton

@rluvatonrluvaton commented Oct 24, 2023

Copy link
Copy Markdown
Member

Benchmarks

Benchmark URL

15:39:36 confidence improvement accuracy (*) (**) (***)
15:39:36 streams/readable-from.js type='array' n=10000000 *** 23.20 % ±9.27% ±12.34% ±16.09%
15:39:36 streams/readable-from.js type='async-generator' n=10000000 * 2.28 % ±1.83% ±2.44% ±3.17%
15:39:36 streams/readable-from.js type='sync-generator-with-async-values' n=10000000 0.48 % ±1.82% ±2.42% ±3.15%
15:39:36 streams/readable-from.js type='sync-generator-with-sync-values' n=10000000 *** 18.26 % ±2.01% ±2.68% ±3.49%

@rluvatonrluvaton added stream Issues and PRs related to the stream subsystem. performance Issues and PRs related to the performance of Node.js. labels Oct 24, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-botnodejs-github-bot added the needs-ci PRs that need a full CI run. label Oct 24, 2023
@rluvatonrluvaton added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 24, 2023
@rluvaton

This comment was marked as outdated.

@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 24, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@ronag

Copy link
Copy Markdown
Member

Not sure I'm convinced the extra complexity is worth it. Let's see what the benchmark says.

@ronag

Copy link
Copy Markdown
Member

@rluvaton when you start a benchmark ci in cases like this, add a filter e,g, from so not all benchmarks run.

@ronag

Copy link
Copy Markdown
Member

https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1457/

@ronag

Copy link
Copy Markdown
Member
11:20:15 streams/readable-from.js type='array' n=10000000 7.03 % ±7.37% ±9.91% ±13.11%
11:20:15 streams/readable-from.js type='async-generator' n=10000000 * 1.64 % ±1.41% ±1.88% ±2.45%
11:20:15 streams/readable-from.js type='sync-generator-with-async-values' n=10000000 1.62 % ±1.68% ±2.24% ±2.92%
11:20:15 streams/readable-from.js type='sync-generator-with-sync-values' n=10000000 *** 11.09 % ±1.82% ±2.42% ±3.16%

Comment threadlib/internal/streams/from.js Outdated
Comment threadlib/internal/streams/from.js Outdated
@ronag

Copy link
Copy Markdown
Member

I'm -0. There is a perf improvement but the maintainability cost is quite high.

@rluvaton

Copy link
Copy Markdown
MemberAuthor

due to the removal of the async modifier I rerun the benchmark:
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1458/

I'm -0. There is a perf improvement but the maintainability cost is quite high.

I'm on the fence as well...

@rluvaton

Copy link
Copy Markdown
MemberAuthor

@ronag Updated the benchmarks...

@rluvatonrluvaton added the request-ci Add this label to start a Jenkins CI on a PR. label Oct 24, 2023
@H4adH4ad added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 24, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 24, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@benjamingr

Copy link
Copy Markdown
Member

I'm tired so if I don't make sense let me know - In the array case can't we just set the stream's buffer to ArrayPrototypeSlice(Input)? With ronag's bufferliist->array PR that could be ideal?

@rluvaton

Copy link
Copy Markdown
MemberAuthor

I'm tired so if I don't make sense let me know - In the array case can't we just set the stream's buffer to ArrayPrototypeSlice(Input)? With ronag's bufferliist->array PR that could be ideal?

it would really improve the performance for sure but wouldn't it be dangerous as we need to make the stream reach the state where it would have data after init and everything

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@ronag

Copy link
Copy Markdown
Member

Wouldn't we skip a lot of state transitions that the user expects?

Not really?

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@benjamingr

Copy link
Copy Markdown
Member

In that case this whole implementation would basically be:

Yeah that was my point in #50359 I think that would be way faster and probably semver-major

@rluvatonrluvaton added the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 25, 2023
@rluvaton

Copy link
Copy Markdown
MemberAuthor

In that case this whole implementation would basically be:

Yeah that was my point in #50359 I think that would be way faster and probably semver-major

Because it needs a semver major, I will create a new PR with the new code after that

@rluvatonrluvaton added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Oct 25, 2023
@rluvatonrluvaton added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Oct 25, 2023
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Oct 25, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Oct 26, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 10d51e8 into nodejs:mainOct 26, 2023
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 10d51e8

@rluvaton
rluvaton deleted the improve-from branch October 26, 2023 09:04
targos pushed a commit that referenced this pull request Nov 11, 2023
PR-URL: #50359
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@targostargos mentioned this pull request Nov 12, 2023
UlisesGascon pushed a commit that referenced this pull request Dec 11, 2023
PR-URL: #50359
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@UlisesGasconUlisesGascon mentioned this pull request Dec 12, 2023
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.needs-ciPRs that need a full CI run.performanceIssues and PRs related to the performance of Node.js.streamIssues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@rluvaton@nodejs-github-bot@ronag@benjamingr@H4ad