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

tls: avoid calling Buffer.byteLength multiple times #7236

Closed
wants to merge 1 commit into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Jun 8, 2016

Checklist
  • make -j4 test (UNIX) or vcbuild test nosign (Windows) passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Affected core subsystem(s)

tls

Description of change

There's no reason to be calling Buffer.byteLength() twice. That's just silly.
Small perf improvement

Run 1:
tls/convertprotocols.js n=1 v6.2.1 = 11852, new = 12204 ...... -2.89%
tls/convertprotocols.js n=50000 v6.2.1 = 515660, new = 570610 ..... -9.63%

Run 2:
tls/convertprotocols.js n=1 v6.2.1 = 11729, new = 12045 ...... -2.62%
tls/convertprotocols.js n=50000 v6.2.1 = 512080, new = 637730 ..... -19.70%

@nodejs/crypto

@jasnell jasnell added the tls Issues and PRs related to the tls subsystem. label Jun 8, 2016
@indutny
Copy link
Member

indutny commented Jun 8, 2016

Is it optimization for the client?

@jasnell
Copy link
Member Author

jasnell commented Jun 8, 2016

client and server, only with ALPN or NPN are passed in as an Array. Very minor and low priority but just happened to spot it.

@@ -35,17 +35,18 @@ exports.getCiphers = function() {
// Convert protocols array into valid OpenSSL protocols list
// ("\x06spdy/2\x08http/1.1\x08http/1.0")
function convertProtocols(protocols) {
var buff = Buffer.allocUnsafe(protocols.reduce(function(p, c) {
return p + 1 + Buffer.byteLength(c);
const lens = {};
Copy link
Member

Choose a reason for hiding this comment

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

Should this be n Array of size protocols.length?

Copy link
Member Author

Choose a reason for hiding this comment

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

it could be, yes.

Copy link
Member

Choose a reason for hiding this comment

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

so new Array(protocols.length) should boost the micro-benchmark? 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

the difference is not even noticeable really. :-)

@mscdex mscdex added the performance Issues and PRs related to the performance of Node.js. label Jun 8, 2016
@jasnell
Copy link
Member Author

jasnell commented Jun 8, 2016

updated!

@indutny
Copy link
Member

indutny commented Jun 9, 2016

LGTM

There's no reason to be calling Buffer.byteLength() twice.
Small perf improvement

Run 1:
tls/convertprotocols.js n=1     v6.2.1 = 11852,  new = 12204 ......  -2.89%
tls/convertprotocols.js n=50000 v6.2.1 = 515660, new = 570610 .....  -9.63%

Run 2:
tls/convertprotocols.js n=1     v6.2.1 = 11729,  new = 12045 ......  -2.62%
tls/convertprotocols.js n=50000 v6.2.1 = 512080, new = 637730 ..... -19.70%
@jasnell jasnell force-pushed the perf-tls-convertprotocols branch from c441764 to e9aaabb Compare June 21, 2016 17:06
@jasnell
Copy link
Member Author

jasnell commented Jun 21, 2016

@jasnell
Copy link
Member Author

jasnell commented Jun 21, 2016

Failures are unrelated. Also, it looks like we're having some CI troubles with a few bots hanging (@nodejs/build)

jasnell added a commit that referenced this pull request Jun 21, 2016
There's no reason to be calling Buffer.byteLength() twice.
Small perf improvement

Run 1:
tls/convertprotocols.js n=1     v6.2.1 = 11852,  new = 12204 ......  -2.89%
tls/convertprotocols.js n=50000 v6.2.1 = 515660, new = 570610 .....  -9.63%

Run 2:
tls/convertprotocols.js n=1     v6.2.1 = 11729,  new = 12045 ......  -2.62%
tls/convertprotocols.js n=50000 v6.2.1 = 512080, new = 637730 ..... -19.70%

PR-URL: #7236
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@jasnell
Copy link
Member Author

jasnell commented Jun 21, 2016

Landed in f3d5efa

@jasnell jasnell closed this Jun 21, 2016
Fishrock123 pushed a commit that referenced this pull request Jun 27, 2016
There's no reason to be calling Buffer.byteLength() twice.
Small perf improvement

Run 1:
tls/convertprotocols.js n=1     v6.2.1 = 11852,  new = 12204 ......  -2.89%
tls/convertprotocols.js n=50000 v6.2.1 = 515660, new = 570610 .....  -9.63%

Run 2:
tls/convertprotocols.js n=1     v6.2.1 = 11729,  new = 12045 ......  -2.62%
tls/convertprotocols.js n=50000 v6.2.1 = 512080, new = 637730 ..... -19.70%

PR-URL: #7236
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@Fishrock123 Fishrock123 mentioned this pull request Jun 27, 2016
Fishrock123 pushed a commit that referenced this pull request Jul 5, 2016
There's no reason to be calling Buffer.byteLength() twice.
Small perf improvement

Run 1:
tls/convertprotocols.js n=1     v6.2.1 = 11852,  new = 12204 ......  -2.89%
tls/convertprotocols.js n=50000 v6.2.1 = 515660, new = 570610 .....  -9.63%

Run 2:
tls/convertprotocols.js n=1     v6.2.1 = 11729,  new = 12045 ......  -2.62%
tls/convertprotocols.js n=50000 v6.2.1 = 512080, new = 637730 ..... -19.70%

PR-URL: #7236
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
@Fishrock123 Fishrock123 mentioned this pull request Jul 5, 2016
@MylesBorins
Copy link
Contributor

@jasnell lts?

@MylesBorins
Copy link
Contributor

This does not land cleanly in LTS. Added dont-land label. Please feel free to manually backport @jasnell

@jasnell
Copy link
Member Author

jasnell commented Oct 10, 2016

This should be fine not to backport.

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. tls Issues and PRs related to the tls subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants