★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/18320Nouvelle recherche | Portail wanayoo
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

benchmarks: improve code base #18320

Closed
wants to merge 10 commits into from
Closed

Conversation

Copy link
Member

@BridgeAR BridgeAR commented Jan 23, 2018

Just some refactoring of some benchmarks to reduce code overhead and improve readability.

I some times changed let in a loop to var because it may theoretically still lead to a deopt / prevent a opt.

I fixed two benchmarks that regressed before and what I realized when going over all files again.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

benchmark

@nodejs-github-bot nodejs-github-bot added assert async_hooks benchmark buffer crypto dgram domain v8 engine labels Jan 23, 2018
Copy link
Member

@apapirovski apapirovski left a comment

LGTM with some nits


bench.start();
for (i = 0; i < n; ++i) {
fn(actual, expected);
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

This doesn't look correct? For the not versions it needs to use expectedWrong, right?

Copy link
Member Author

@BridgeAR BridgeAR Jan 24, 2018

Choose a reason for hiding this comment

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

You are absolutely correct. While looking over the file I missed that.

case 'deepStrictEqual':
bench.start();
for (i = 0; i < n; ++i) {
assert.deepStrictEqual(actual, expected);
fn(actual, expected);
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

Could this be more similar to the change above but just assign expected/expectedWrong to a diff variable as necessary. Then the for loops, etc. don't need to be part of the switch.

Same for all of the similar use cases below.

Copy link
Member Author

@BridgeAR BridgeAR Jan 24, 2018

Choose a reason for hiding this comment

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

Done

let s = '';
let i;
var s = '';
var i;
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

I don't think this change is necessary since the let is not declared within the for loop and for general usage it was optimized quite a while ago.

var strings = [ Buffer.alloc(len * 16, 'a') ];
var results = [ len * 16 ];

if (encoding !== 'buffer') {
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

I don't think this change is quite right. It means the Buffer is always the first element of strings even though it shouldn't be. I would prefer to leave this benchmark as is. The only change I can see is not allocating the empty array in strings and instead allocating it within the else branch.

bench.start();
testFunction(buff);
bench.end(len / 1e6);
for (var i = 0; i !== millions * 1e6; i++) {
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

millions * 1e6 will happen on every iteration of the loop. I would prefer it assigned to a const.

Copy link
Member Author

@BridgeAR BridgeAR Jan 24, 2018

Choose a reason for hiding this comment

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

I did not check but I am pretty certain that the compiler creates a constant internally after evaluating the computation.

Copy link
Member

@apapirovski apapirovski Jan 24, 2018

Choose a reason for hiding this comment

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

I know that's sort of the case with length but I wonder in this case... ping @bmeurer

Copy link
Member

@bmeurer bmeurer Jan 25, 2018

Choose a reason for hiding this comment

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

TurboFan should sort that out, yes.

Copy link
Member Author

@BridgeAR BridgeAR Jan 27, 2018

Choose a reason for hiding this comment

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

@apapirovski I personally would like to get rid of "millions" and use "n" instead. But for now I would just stick to the way I changed it.

But I am also fine with removing that change again as it is not important at all. What do you prefer?

bench.start();
testFunction(buff);
bench.end(len / 1e6);
for (var i = 0; i !== millions * 1e6; i++) {
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

Same as above. There are a few more of these in the files below too...

@@ -28,7 +28,7 @@ function main({ n, pathext }) {

bench.start();
for (var i = 0; i < n; i++) {
posix.basename(pathext, ext);
win32.basename(pathext, ext);
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

Nice catch.

var m = {};
// First call dominates results
if (n > 1) {
tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m);
m = {};
}
bench.start();
for (; i < n; i++) tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m);
for (var i = 0; i < n; i++)
tls.convertNPNProtocols(['ABC', 'XYZ123', 'FOO'], m);
Copy link
Member

@apapirovski apapirovski Jan 23, 2018

Choose a reason for hiding this comment

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

Can we store the array in a variable in addition to this change? The results here are probably dominated by the array creation.

@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR commented Jan 24, 2018

@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR commented Jan 24, 2018

@apapirovski
Copy link
Member

@apapirovski apapirovski commented Jan 24, 2018

@BridgeAR looks like one of the assert benchmarks is broken, or if not then at the very least the test that runs them.

@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR commented Jan 27, 2018

@BridgeAR BridgeAR added the author ready label Jan 30, 2018
@BridgeAR
Copy link
Member Author

@BridgeAR BridgeAR commented Feb 1, 2018

@MylesBorins
Copy link
Member

@MylesBorins MylesBorins commented Mar 20, 2018

Should this be backported to v8.x-staging or v6.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
It should say `win32` and not `posix`.

PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
Due to the destructuring the outer variables were not set anymore.

PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
MayaLekova pushed a commit to MayaLekova/node that referenced this issue May 8, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
@ryzokuken
Copy link
Member

@ryzokuken ryzokuken commented Jun 6, 2018

@MylesBorins looks like this one's pending a backport? I'll love to give it a shot.

Also, do I still need to backport it to v6? When it landed, v6 wasn't in maintenance, but it is now.

@MylesBorins
Copy link
Member

@MylesBorins MylesBorins commented Jun 6, 2018

It does not need to be backported to 6. Lmk of you need help with 8 at all

@ryzokuken
Copy link
Member

@ryzokuken ryzokuken commented Jun 6, 2018

@MylesBorins this looks super tricky because there's a change that landed later (but got backported before), that seems to have refactored almost everything.

For example, take a look at:

screen shot 2018-06-06 at 2 43 51 pm

in here, which change do I accept? Accepting the current change looks like a nice thing to do but I'll have to manually remove the last 4 lines (is that okay?). Accepting the incoming change won't work because it needs the method variable.

@MylesBorins
Copy link
Member

@MylesBorins MylesBorins commented Jun 6, 2018

@ryzokuken I would suggest trying to get a result that is closest to what is upstream (in master) (if that makes sense)

@ryzokuken
Copy link
Member

@ryzokuken ryzokuken commented Jun 6, 2018

P.S. Do I accept both and modify the solutions (mix and match)? That doesn't sound like something that should happen without the consent of the PR owner, given that such a thing might completely go against what they initially intended.

@ryzokuken
Copy link
Member

@ryzokuken ryzokuken commented Jun 6, 2018

@ryzokuken I would suggest trying to get a result that is closest to what is upstream (if that makes sense)

Only keep stuff from the PR (incoming changes) that has 0 conflicts and is absolutely necessary, you mean?

@ryzokuken
Copy link
Member

@ryzokuken ryzokuken commented Jun 6, 2018

@MylesBorins there are files that were removed later. Should I re-add them with the changed version?

ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
It should say `win32` and not `posix`.

PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
Due to the destructuring the outer variables were not set anymore.

PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
ryzokuken pushed a commit to ryzokuken/node that referenced this issue Jun 6, 2018
PR-URL: nodejs#18320
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR BridgeAR deleted the improve-benchmarks branch Apr 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert async_hooks benchmark buffer crypto dgram domain v8 engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants