Skip to content

Conversation

@adrian-nitu-92
Copy link
Contributor

@adrian-nitu-92adrian-nitu-92 commented Jul 11, 2016

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

buffer

Description of change

We are currently analyzing the buffer-indexof performance and noticed that a
considerable amount of time is spent in the isNan() function.
By postponing the isNan check we noticed a performance boost.

Signed-off-by: Adrian Nițu [email protected]

@nodejs-github-botnodejs-github-bot added the buffer Issues and PRs related to the buffer subsystem. label Jul 11, 2016
@cjihrig
Copy link
Contributor

Do you have performance numbers for this?

lib/buffer.js Outdated
Copy link
Contributor

@mscdexmscdexJul 11, 2016

Choose a reason for hiding this comment

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

Missing indentation

@adrian-nitu-92
Copy link
ContributorAuthor

Performance numbers available at, as measured on:

uname -a Linux anitu-desk 4.6.2-1-ARCH #1 SMP PREEMPT Wed Jun 8 08:40:59 CEST 2016 x86_64 GNU/Linux 

cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 60 model name : Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz stepping : 3 microcode : 0x1c cpu MHz : 4389.218 cache size : 8192 KB .... 

@adrian-nitu-92
Copy link
ContributorAuthor

Implemented requested changes :D

@mscdex
Copy link
Contributor

mscdex commented Jul 12, 2016

What if we just changed the isNaN(byteOffset) to byteOffset !== byteOffset and nothing else? That should simplify the changes while achieving the original performance goal.

@adrian-nitu-92
Copy link
ContributorAuthor

I looked into that, it gets slightly lower performance(under 1% lower).
The middle ground would be something like the general case gets a free bypass and then use the original code :)

@adrian-nitu-92
Copy link
ContributorAuthor

Any comments on the (typeof byteOffset === 'string') condition?

It feels really awkward :D

@mscdex
Copy link
Contributor

mscdex commented Jul 12, 2016

typeof byteOffset === 'string' is just fine since it's checking for an optional argument. That particular conditional is checking if byteOffset was not provided, but the encoding was. This can be checked only because the two parameters are different types.

@adrian-nitu-92
Copy link
ContributorAuthor

So I gather I should just simplify the patch according to mscdex's comments and resend my patch

@jasnell
Copy link
Member

@adrian-nitu-92 ... sorry for the delay, updating this PR would be the way to do it. If you're still interested in moving this forward, simply add the new commits here and we'll take a look! :-)

We are currently analyzing the buffer-indexof performance and noticed that a considerable amount of time is spent in the isNan() function. By simplifying this check we notice a small perf boost. Signed-off-by: Adrian Nitu <[email protected]>
@adrian-nitu-92
Copy link
ContributorAuthor

Thank you for the feedback, I simplified my patch

@Trott
Copy link
Member

Trott commented Sep 7, 2016

@nodejs/buffer @nodejs/benchmarking @mscdex

@imyller
Copy link
Member

Copy link
Member

@jasnelljasnell left a comment

Choose a reason for hiding this comment

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

LGTM

@ThePrimeagen
Copy link
Member

ThePrimeagen commented Sep 27, 2016

@adrian-nitu-92 could you put a comment explaining what you are doing? Its clever, and clever often leads to misunderstanding. A quick comment should alleviate what looks like a bug.

The comment below is somewhat misleading, you could also just clean that up.

@jasnelljasnell added the stalled Issues and PRs that are stalled. label Jan 6, 2017
@jasnell
Copy link
Member

Is this still something that should happen?

@mscdex
Copy link
Contributor

mscdex commented Jan 6, 2017

I think adding a comment above the conditional might be a good idea. Either way it LGTM.

Copy link
Member

@mhdawsonmhdawson left a comment

Choose a reason for hiding this comment

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

I agree adding a comment explaining what and how the check accomplishes would be useful. Its not obvious otherwise

@trevnorris
Copy link
Contributor

Would be worth it to run this with Number.isNaN(byteOffset). Since the operation just above it already coerces the value, should be able to do a more direct check.

@mscdex
Copy link
Contributor

@trevnorris I'm not sure it'd be worth it since it needs to be converted anyway?

@trevnorris
Copy link
Contributor

@mscdex What I mean is that because of:

byteOffset=+byteOffset;// Coerce to Number.

we can use the more strict Numer.isNaN() rather than the generic.

@mscdex
Copy link
Contributor

mscdex commented Jan 28, 2017

@trevnorris The n !== n style of NaN checking seems to be faster than Number.isNaN(n).

@trevnorris
Copy link
Contributor

@mscdex Hm. Seems the code was updated to use !== between my last two comments, but I didn't look at the change before my last comment. Change looks good.

@Trott
Copy link
Member

#12286 seems to duplicate this and include some other things (a benchmark file, a comment explaining why it's doing things this way, and implementing the same change where Number.isNan() is used in one other place in the file. I'm going to close this in favor of that PR, but feel free to comment or re-open if you think this should stay open. Thanks for the PR!

@TrottTrott closed this Apr 14, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bufferIssues and PRs related to the buffer subsystem.stalledIssues and PRs that are stalled.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@adrian-nitu-92@cjihrig@mscdex@jasnell@Trott@imyller@ThePrimeagen@trevnorris@mhdawson@nodejs-github-bot