Skip to content

crypto: make createXYZ inlineable - #16067

Closed
mcollina wants to merge 1 commit into
nodejs:masterfrom
mcollina:change-hash-constructor
Closed

crypto: make createXYZ inlineable#16067
mcollina wants to merge 1 commit into
nodejs:masterfrom
mcollina:change-hash-constructor

Conversation

@mcollina

@mcollinamcollina commented Oct 7, 2017

Copy link
Copy Markdown
Member

This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.

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

crypto

@mcollina
mcollina requested a review from jasnellOctober 7, 2017 18:27
@nodejs-github-botnodejs-github-bot added the crypto Issues and PRs related to the crypto subsystem. label Oct 7, 2017
@mcollina

Copy link
Copy Markdown
MemberAuthor

This is just an example. We should do the same for all the rest of the createXYZ methods in crypto, and maybe in other places as well.

@mcollina
mcollina requested a review from bmeurerOctober 7, 2017 18:30
@mscdex

Copy link
Copy Markdown
Contributor

Yes, I think we should be doing it for the rest as well.

@mscdexmscdex added the performance Issues and PRs related to the performance of Node.js. label Oct 7, 2017
@mcollina

Copy link
Copy Markdown
MemberAuthor

The reason it was not inlining was with the following output:

Not inlining Hash into etag because call is recursive

@mcollina

Copy link
Copy Markdown
MemberAuthor

@mscdex do you prefer if we do all of them here, or we do this into separate PRs?

@TimothyGuTimothyGu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the understanding that this is going to be done with all the other creation functions, LGTM.

@bmeurerbmeurer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

For the record: We removed the recursive inlining restriction recently.

@mcollina

Copy link
Copy Markdown
MemberAuthor

@bmeurer is this worth doing then? In which version of V8 this is going to be part of?
The problem I describe is still present in node master.

@mcollina
mcollinaforce-pushed the change-hash-constructor branch from 625e27b to a6a2f89CompareOctober 7, 2017 18:51
@mcollinamcollina changed the title crypto: make createHash inlineablecrypto: make createXYZ inlineableOct 7, 2017
@mcollina

Copy link
Copy Markdown
MemberAuthor

I have ported all the createXYZ functions.

@mscdex

mscdex commented Oct 7, 2017

Copy link
Copy Markdown
Contributor

I think it's worth doing for now, especially for node v8.x which may not see the version of V8 where the fixed is applied.

@mscdex

Copy link
Copy Markdown
Contributor

Comment threadlib/crypto.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a quick comment explaining the optimization.

@mcollina
mcollinaforce-pushed the change-hash-constructor branch from a6a2f89 to 6042f8eCompareOctober 7, 2017 21:37
@mcollina

Copy link
Copy Markdown
MemberAuthor

@bengl done.

@bmeurer

Copy link
Copy Markdown
Member

@mcollina I just noticed that we still disallow direct recursive inlining (as of 08bfcb293cfff2d71bcfb28fae8679d0b29a3d5c), so even though indirect recursion is handled, direct recursion is not.

These changes are in V8 6.2. So for Node 8 it definitely makes sense to land this change.

Comment threadlib/crypto.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor nits:

s/function/helper functions/

Also, might use more generic wording like 'These helper functions are needed because the constructors can use new, in which case V8 cannot inline the recursive constructor call' or something along those lines.

This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
@mcollina
mcollinaforce-pushed the change-hash-constructor branch from 6042f8e to 4e61acbCompareOctober 9, 2017 07:30
@mcollina

Copy link
Copy Markdown
MemberAuthor

@mcollina

Copy link
Copy Markdown
MemberAuthor

Landed as 9bc4f86

@mcollinamcollina closed this Oct 9, 2017
@mcollina
mcollina deleted the change-hash-constructor branch October 9, 2017 09:43
mcollina added a commit that referenced this pull request Oct 9, 2017
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
PR-URL: #16067
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 12, 2017
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
PR-URL: nodejs/node#16067
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins

Copy link
Copy Markdown
Contributor

This does not land cleanly on v8.x

Would someone be willing to backport if it makes sense?

@lpinca

Copy link
Copy Markdown
Member
assert.strictEqual(crypto.createHash,crypto.Hash);

et al. throw with this change, should we backport anyway?

@MylesBorins

Copy link
Copy Markdown
Contributor

@lpinca if it is breaking than this should likely be tagged semver-major, if not then I don't see why we shouldn't backport

@lpinca

Copy link
Copy Markdown
Member

@MylesBorins yes exactly I'm not sure if it's a breaking change or not.

@MylesBorinsMylesBorins added the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 24, 2017
@MylesBorins

Copy link
Copy Markdown
Contributor

setting semver-major for right now

/cc @nodejs/tsc to chime in. Feel free to change tag

@mcollina

Copy link
Copy Markdown
MemberAuthor

According to our doc, this is patch. if people are calling createHash with new, probably they are doing somethig wrong. This can go in 8. Or we can bake it for a bit on 9 and then backport to 8.
Most of the discussion in this issue is about landing it in 8.

@jasnell

Copy link
Copy Markdown
Member

I'm +1 on it being semver-patch.

lpinca pushed a commit to lpinca/node that referenced this pull request Oct 24, 2017
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
PR-URL: nodejs#16067
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@lpinca

Copy link
Copy Markdown
Member

Backport in #16446 marked as blocked currently.

@MylesBorinsMylesBorins removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Oct 24, 2017
@MylesBorins

Copy link
Copy Markdown
Contributor

dropping semver-major. Thinking we should let this bake in 9.x a bit first

gibfahn pushed a commit that referenced this pull request Dec 19, 2017
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
PR-URL: #16067
Backport-PR-URL: #16446
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@gibfahngibfahn mentioned this pull request Dec 20, 2017
gibfahn pushed a commit that referenced this pull request Dec 20, 2017
This commit increase by around 10% hot code paths that are hitting
createXYZ functions. Before this change the createXYZ called the XYZ
constructor without new.
PR-URL: #16067
Backport-PR-URL: #16446
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yosuke Furukawa <yosuke.furukawa@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@gibfahngibfahn mentioned this pull request Dec 20, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cryptoIssues and PRs related to the crypto subsystem.performanceIssues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

14 participants

@mcollina@mscdex@bmeurer@MylesBorins@lpinca@jasnell@bengl@yosuke-furukawa@evanlucas@TimothyGu@cjihrig@BridgeAR@BethGriggs@nodejs-github-bot