Uh oh!
There was an error while loading. Please reload this page.
http: speed up checkIsHttpToken - #4790
Conversation
mscdex
commented
Jan 21, 2016
Can you add a comment above // This implementation of checkIsHttpToken() loops over the string instead of// using a regular expression since the former is up to 180% faster with v8 4.7// depending on the string length (the shorter the string, the larger the// performance difference) |
mscdex
commented
Jan 21, 2016
There was a problem hiding this comment.
constlen=val.length;for(leti=0;i<len;i++){Not sure if it matters or improves anything.
There was a problem hiding this comment.
It means the same, so shouldn't matter.
jasnell
commented
Jan 21, 2016
LGTM |
26fd567 to
6f7e790Comparejasnell
commented
Jan 23, 2016
@mscdex ... can I ask you to take another look? |
mscdex
commented
Jan 23, 2016
LGTM if CI is still ok with it: https://ci.nodejs.org/job/node-test-pull-request/1356/ |
ChALkeR
commented
Jan 24, 2016
@JacksonTian Most probably things didn't change, but just in case — could you rebase against current master and re-run the benchmarks, please? v8 4.8 has landed to |
There was a problem hiding this comment.
This comment probably should also be updated to reflect the situation on v8 4.8 (that most likely didn't change, but still it would be better to re-check that).
There was a problem hiding this comment.
Well if it performs the same, the comment is fine as-is.
ronkorving
commented
Jan 25, 2016
@JacksonTian It seems that the benchmark is currently not checking strings (short and long) that are not valid tokens. Adding those would complete the picture. |
JacksonTian
commented
Jan 25, 2016
Thanks, @ronkorving , should check the length of string. |
ChALkeR
commented
Jan 25, 2016
@ronkorving Note that strings that are not valid tokens should be never hit in valid code, and definitely they wouldn't be in the hot code path. |
ronkorving
commented
Jan 25, 2016
@ChALkeR I'm aware that they would not be in the hot code path, but it can happen in valid code, can't it? (I can send whatever I want to your server). |
jasnell
commented
Jan 25, 2016
Just a quick note... This function is not called when an http message is received and parsed. This is only and called when a header is set, and yes, it's whole point is to make sure the input is valid. Benchmarking with invalid input makes sense. |
6f7e790 to
8cfc0f8CompareJacksonTian
commented
Jan 25, 2016
Updated the benchmarks: $ ./node benchmark/compare.js ./node ~/.tnvm/versions/node/v5.5.0/bin/node -- http check_is_http_token.js
running ./node
http/check_is_http_token.js
running /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node
http/check_is_http_token.js
http/check_is_http_token.js key=TCN n=1000000: ./node: 51572000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 15310000 ................. 236.86%
http/check_is_http_token.js key=ETag n=1000000: ./node: 48290000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 17196000 ................ 180.82%
http/check_is_http_token.js key=date n=1000000: ./node: 36327000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 18460000 ................. 96.79%
http/check_is_http_token.js key=Vary n=1000000: ./node: 41768000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 15744000 ................ 165.30%
http/check_is_http_token.js key=server n=1000000: ./node: 26680000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 15540000 ............... 71.68%
http/check_is_http_token.js key=Server n=1000000: ./node: 30184000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 12586000 .............. 139.83%
http/check_is_http_token.js key=status n=1000000: ./node: 31065000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 14091000 .............. 120.46%
http/check_is_http_token.js key=version n=1000000: ./node: 27162000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 14666000 .............. 85.21%
http/check_is_http_token.js key=Expires n=1000000: ./node: 23853000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 13385000 .............. 78.21%
http/check_is_http_token.js key=alt-svc n=1000000: ./node: 27987000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 12539000 ............. 123.20%
http/check_is_http_token.js key=location n=1000000: ./node: 21943000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 13265000 ............. 65.42%
http/check_is_http_token.js key=Connection n=1000000: ./node: 19229000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 12365000 ........... 55.51%
http/check_is_http_token.js key=Keep-Alive n=1000000: ./node: 17815000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 13648000 ........... 30.54%
http/check_is_http_token.js key=content-type n=1000000: ./node: 16488000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 13965000 ......... 18.06%
http/check_is_http_token.js key=Content-Type n=1000000: ./node: 17237000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 12495000 ......... 37.95%
http/check_is_http_token.js key=Cache-Control n=1000000: ./node: 14031000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 13030000 ......... 7.69%
http/check_is_http_token.js key=Last-Modified n=1000000: ./node: 14797000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 9009100 ......... 64.25%
http/check_is_http_token.js key=Accept-Ranges n=1000000: ./node: 13960000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 11130000 ........ 25.43%
http/check_is_http_token.js key=content-length n=1000000: ./node: 13729000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 11711000 ....... 17.23%
http/check_is_http_token.js key=x-frame-options n=1000000: ./node: 11441000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 10915000 ....... 4.82%
http/check_is_http_token.js key=x-xss-protection n=1000000: ./node: 11358000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 11408000 ..... -0.44%
http/check_is_http_token.js key=Content-Encoding n=1000000: ./node: 13669000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 4164100 ..... 228.25%
http/check_is_http_token.js key=Content-Location n=1000000: ./node: 12569000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 11012000 ..... 14.14%
http/check_is_http_token.js key=Transfer-Encoding n=1000000: ./node: 12057000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 11340000 ..... 6.33%
http/check_is_http_token.js key=alternate-protocol n=1000000: ./node: 9157300 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 10027000 .... -8.67%
http/check_is_http_token.js key=: n=1000000: ./node: 58233000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 22897000 ................... 154.33%
http/check_is_http_token.js key=@@ n=1000000: ./node: 60918000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 23144000 .................. 163.21%
http/check_is_http_token.js key=中文呢 n=1000000: ./node: 56176000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 22926000 ................. 145.03%
http/check_is_http_token.js key=((((()))) n=1000000: ./node: 49334000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 20424000 ........... 141.55%
http/check_is_http_token.js key=:alternate-protocol n=1000000: ./node: 62579000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 21284000 . 194.02%
http/check_is_http_token.js key=alternate-protocol: n=1000000: ./node: 10406000 /Users/jacksontian/.tnvm/versions/node/v5.5.0/bin/node: 8494400 ... 22.51% |
ronkorving
commented
Jan 25, 2016
@jasnell thanks for the feedback on that |
jasnell
commented
Jan 27, 2016
LGTM... one last CI run just to be safe: https://ci.nodejs.org/job/node-test-pull-request/1401/ |
jasnell
commented
Mar 22, 2016
Looks like this one slipped by... old CI run is no longer available. New CI here: https://ci.nodejs.org/job/node-test-pull-request/2007/ |
jasnell
commented
Mar 22, 2016
Looks like there are some linting issues: https://ci.nodejs.org/job/node-test-linter/1756/console |
jasnell
commented
Mar 22, 2016
Sigh.. scratch that on the linting issue. That was my bad. New CI: https://ci.nodejs.org/job/node-test-pull-request/2012/ |
jasnell
commented
Mar 22, 2016
Heh... turns out there is a linting issue here afterall ;-) |
There was a problem hiding this comment.
benchmark needs 'use strict'; at the top
8cfc0f8 to
72e7e68CompareThe Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result
72e7e68 to
e7246d1CompareJacksonTian
commented
Mar 22, 2016
Hi @jasnell , I updated the commit, and new benchmark result: |
jasnell
commented
Mar 22, 2016
jasnell
commented
Mar 22, 2016
CI is green. LGTM |
jasnell
commented
Mar 22, 2016
@indutny ... any final comments on this before I land? |
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
jasnell
commented
Mar 27, 2016
Landed in 089c6a4 |
jasnell
commented
Mar 27, 2016
@thealphanerd ... let's hold off landing this in v4 until it's been in v5 for a while. |
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
MylesBorins
commented
May 17, 2016
@jasnell should we include this in v4.5.0? |
jasnell
commented
May 17, 2016
It's likely safe |
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The Regex implementation is not faster than ascii code compare. the field name is shorter, the speed is faster. benchmark result here: https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result PR-URL: #4790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
The Regex implementation is not faster than ascii code compare.
the field name is shorter, the speed is faster.
benchmark result here:
https://bitbucket.org/snippets/JacksonTian/Rnbad/benchmark-result