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

stream: improve read() performance more #28989

Merged
merged 1 commit into from
Aug 9, 2019

Conversation

mscdex
Copy link
Contributor

@mscdex mscdex commented Aug 6, 2019

Results:

                                                        confidence improvement accuracy (*)    (**)   (***)
 streams/readable-bigread.js n=1000                           ***     43.35 %       ±2.61%  ±3.50%  ±4.61%
 streams/readable-bigunevenread.js n=1000                     ***     26.71 %       ±8.11% ±10.83% ±14.17%
 streams/readable-unevenread.js n=1000                        ***      3.42 %       ±1.13%  ±1.50%  ±1.96%
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@mscdex mscdex added stream Issues and PRs related to the stream subsystem. performance Issues and PRs related to the performance of Node.js. labels Aug 6, 2019
@nodejs-github-bot
Copy link
Collaborator

if (nb === buf.length)
ret.set(buf, ret.length - n);
else
ret.set(new Uint8Array(buf.buffer, buf.byteOffset, nb), ret.length - n);
Copy link
Member

Choose a reason for hiding this comment

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

how does this differ from copy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a tad faster.

Copy link
Member

Choose a reason for hiding this comment

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

yes, just confused as two how it can be faster. Some V8 thingy?

Copy link
Member

Choose a reason for hiding this comment

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

yes. v8 can optimize the stuff it provides, but our buffer copy is basically a black box to it, since its written in c++. we could probably optimize our copy impl to use typedarray's set if there are no source offsets passed.

Copy link
Member

Choose a reason for hiding this comment

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

wouldn't it better to apply this there then?

@ronag
Copy link
Member

ronag commented Aug 9, 2019

Doesn't #29066 supersede this PR?

@mscdex
Copy link
Contributor Author

mscdex commented Aug 9, 2019

@ronag Not really, buffer.copy() has to perform a lot of additional checks that we can skip because of some assumptions we can safely make inside this function.

PR-URL: nodejs#28989
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
@mscdex mscdex merged commit 53e467d into nodejs:master Aug 9, 2019
@mscdex mscdex deleted the streams-readable-perf2 branch August 9, 2019 22:34
targos pushed a commit that referenced this pull request Aug 19, 2019
PR-URL: #28989
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Issues and PRs related to the performance of Node.js. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants