Skip to content

tls: avoid calling Buffer.byteLength multiple times - #7236

Closed
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:perf-tls-convertprotocols
Closed

tls: avoid calling Buffer.byteLength multiple times#7236
jasnell wants to merge 1 commit into
nodejs:masterfrom
jasnell:perf-tls-convertprotocols

Conversation

@jasnell

@jasnelljasnell commented Jun 8, 2016

Copy link
Copy Markdown
Member
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

@jasnelljasnell added the tls Issues and PRs related to the tls subsystem. label Jun 8, 2016
@indutny

Copy link
Copy Markdown
Member

Is it optimization for the client?

@jasnell

Copy link
Copy Markdown
MemberAuthor

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.

Comment threadlib/tls.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.

Should this be n Array of size protocols.length?

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
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
Copy Markdown
MemberAuthor

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. :-)

@mscdexmscdex added the performance Issues and PRs related to the performance of Node.js. label Jun 8, 2016
@jasnell

Copy link
Copy Markdown
MemberAuthor

updated!

@indutny

Copy link
Copy Markdown
Member

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
jasnellforce-pushed the perf-tls-convertprotocols branch from c441764 to e9aaabbCompareJune 21, 2016 17:06
@jasnell

Copy link
Copy Markdown
MemberAuthor

@jasnell

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

Landed in f3d5efa

@jasnelljasnell 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>
@Fishrock123Fishrock123 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>
@Fishrock123Fishrock123 mentioned this pull request Jul 5, 2016
@MylesBorins

Copy link
Copy Markdown
Contributor

@jasnell lts?

@MylesBorins

Copy link
Copy Markdown
Contributor

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

@jasnell

Copy link
Copy Markdown
MemberAuthor

This should be fine not to backport.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performanceIssues and PRs related to the performance of Node.js.tlsIssues and PRs related to the tls subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jasnell@indutny@MylesBorins@mscdex