Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: include webstreams benchmark #45876

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

RafaelGSS
Copy link
Member

This PR includes some basic benchmarks for Readable and Writable web streams. @jasnell do you think we should measure something in particular?

It's on my radar to improve the performance of web streams, but I'm not sure how fair is to compare it with regular streams.

@nodejs-github-bot nodejs-github-bot added the benchmark Issues and PRs related to the benchmark subsystem. label Dec 15, 2022
function main({ n, kind }) {
switch (kind) {
case 'ReadableStream':
new ReadableStream({});
Copy link
Member

Choose a reason for hiding this comment

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

It's better to assign the value to a binding outside the loop and do something about it in the end, otherwise the optimizing compiler might be smart enough to perform a dead code elimination and make the benchmark pointless.

Copy link
Member

@joyeecheung joyeecheung Dec 15, 2022

Choose a reason for hiding this comment

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

A typical technique for micro-benchmarking JS would be to pre-fill an array before the measurement starts, and you assign the values into that array during the benchmark (but do not grow or shrink it), then do something about the array in the end, in general the optimizing compiler won't attempt to eliminate the initializations in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have a way to find dead code elimination? I tried some time ago with some V8 flags but it didn't work.

I've updated the code, does it solve? The benchmark results are the same.

Copy link
Member

@joyeecheung joyeecheung Dec 16, 2022

Choose a reason for hiding this comment

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

Do we have a way to find dead code elimination? I tried some time ago with some V8 flags but it didn't work.

You can try --trace-turbo* flags with --turbo-filter to filter out specific functions you want to take a look at (and use v8/tools/turbolizer to help looking at the output). But I'd say to benchmark Node.js's JS code the best solution is to just avoid micro-benchmarks and test a comprehensive combination of operations with varied input ;) e.g. the pipe-to benchmarks are less likely to be influenced by that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. I've created the creation.js to compare with streams/creation.js. This also shows how much memory it consumes (potential memory leak at some point IMHO - if you use the same n as streams it will get OOM).

Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

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

Can you add a test file for testing the benchmark? Like: test/benchmark/test-webstreams.js

@RafaelGSS RafaelGSS force-pushed the benchmark/add-webstream branch from e880275 to 846b57b Compare December 16, 2022 02:45
@RafaelGSS RafaelGSS force-pushed the benchmark/add-webstream branch from 846b57b to 931c086 Compare December 16, 2022 12:45
@RafaelGSS RafaelGSS force-pushed the benchmark/add-webstream branch from 931c086 to 0432fd4 Compare December 17, 2022 22:28
@RafaelGSS RafaelGSS requested a review from anonrig December 19, 2022 18:06
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Dec 19, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 19, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@RafaelGSS RafaelGSS added the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 21, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 21, 2022
@nodejs-github-bot nodejs-github-bot merged commit 70d269d into nodejs:main Dec 21, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 70d269d

targos pushed a commit that referenced this pull request Jan 1, 2023
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #45876
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request Jan 2, 2023
RafaelGSS added a commit that referenced this pull request Jan 4, 2023
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #45876
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
RafaelGSS added a commit that referenced this pull request Jan 5, 2023
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #45876
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
juanarbol pushed a commit that referenced this pull request Jan 26, 2023
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #45876
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
@juanarbol juanarbol mentioned this pull request Jan 28, 2023
juanarbol pushed a commit that referenced this pull request Jan 31, 2023
Signed-off-by: RafaelGSS <[email protected]>
PR-URL: #45876
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
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. benchmark Issues and PRs related to the benchmark subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants