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

querystring: improve querystring unescapeBuffer perf #12525

Closed
wants to merge 4 commits into from

Conversation

jseijas
Copy link

@jseijas jseijas commented Apr 19, 2017

Refactored the unescapeBuffer function in order to simplify it,
and also to improve the performance.

The benchmark:

querystring/querystring-unescapebuffer.js n=1000000 input="%20%21%2..."
   18.10 %        *** 6.671620e-29
querystring/querystring-unescapebuffer.js n=1000000 input="there%20..."
   2.75 %          * 1.775320e-02
querystring/querystring-unescapebuffer.js n=1000000 input="there%2Q..."
   34.12 %        *** 8.074612e-25
querystring/querystring-unescapebuffer.js n=1000000 input="there is..."
   27.92 %        *** 4.923348e-29
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)

Refactored the unescapeBuffer function in order to simplify it,
and also to improve the performance.

The benchmark:

```improvement confidence      p.value
querystring/querystring-unescapebuffer.js n=1000000 input="%20%21%2..."
   18.10 %        *** 6.671620e-29
querystring/querystring-unescapebuffer.js n=1000000 input="there%20..."
   2.75 %          * 1.775320e-02
querystring/querystring-unescapebuffer.js n=1000000 input="there%2Q..."
   34.12 %        *** 8.074612e-25
querystring/querystring-unescapebuffer.js n=1000000 input="there is..."
   27.92 %        *** 4.923348e-29
```
@nodejs-github-bot nodejs-github-bot added the querystring Issues and PRs related to the built-in querystring module. label Apr 19, 2017
@vsemozhetbyt vsemozhetbyt added the performance Issues and PRs related to the performance of Node.js. label Apr 19, 2017
@vsemozhetbyt
Copy link
Contributor

}


Copy link
Contributor

Choose a reason for hiding this comment

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

Unnecessary whitespace change

Copy link
Author

Choose a reason for hiding this comment

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

What is the standard? Because the file contains both 2 and 1 line separation between functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

My own opinion is that such changes should be addressed separately.

if (c === 37 /*'%'*/ && index < maxLength) {
c = s.charCodeAt(++index);
n = unhexTable[c];
if (n < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work for characters not in the table. This is why I had used !(n >= 0), which will cover undefined as well.

} else {
c1 = s.charCodeAt(++index);
m = unhexTable[c1];
if (m < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@mscdex
Copy link
Contributor

mscdex commented Apr 19, 2017

The subsystem target in the commit message should be querystring instead of lib.

@jseijas jseijas changed the title lib: improve querystring unescapeBuffer perf querystring: improve querystring unescapeBuffer perf Apr 19, 2017
@jseijas
Copy link
Author

jseijas commented Apr 19, 2017

@mscdex subsystem changed, also the three changes asked commited.

if (c === 37 /*'%'*/ && index < maxLength) {
c = s.charCodeAt(++index);
n = unhexTable[c];
if !(n >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing parens. These sorts of things should be caught by make jslint.

} else {
c1 = s.charCodeAt(++index);
m = unhexTable[c1];
if !(m >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

@jseijas
Copy link
Author

jseijas commented Apr 19, 2017

@mscdex sorry, fixed, lint passing ok, also tests.

break;
var index = 0;
var outIndex = 0;
var c, c1, n, m;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we name these better and place them on separate lines?

@mscdex
Copy link
Contributor

mscdex commented Apr 24, 2017

My benchmark results seem to agree more or less with those already posted.

Rename variables and separate in lines.
@jseijas
Copy link
Author

jseijas commented Apr 25, 2017

@mscdex Variables renamed and separated in lines. Lint passing. UT passing. Benchmark times remains similar.

@mscdex
Copy link
Contributor

mscdex commented Apr 25, 2017

@jseijas
Copy link
Author

jseijas commented May 23, 2017

Hi @mscdex! Do you need more changes to be made, or you are ok with this? I see that not all the CI is passing :(

@lpinca
Copy link
Member

lpinca commented May 23, 2017

@mscdex
Copy link
Contributor

mscdex commented May 23, 2017

@jseijas It's fine if CI still checks out and there are no performance regressions. Can you please rebase against current master and re-run the benchmarks? I think V8 5.8 was added since this PR was opened and may/may not have an impact on this.

@jseijas
Copy link
Author

jseijas commented May 23, 2017

@mscdex Of course I can :) I will come back with the results.

@jseijas
Copy link
Author

jseijas commented May 23, 2017

@mscdex Done. Now is even better.

 querystring/querystring-unescapebuffer.js n=1000000 input="%20%21%2..."
    25.54 %        *** 5.020680e-28
 querystring/querystring-unescapebuffer.js n=1000000 input="there%20..."           
    16.14 %        *** 2.536763e-22
 querystring/querystring-unescapebuffer.js n=1000000 input="there%2Q..."                        
    22.93 %        *** 3.068218e-17
 querystring/querystring-unescapebuffer.js n=1000000 input="there is..."                                            
    35.53 %        *** 4.584131e-27

@mscdex
Copy link
Contributor

mscdex commented May 24, 2017

LGTM

@lpinca
Copy link
Member

lpinca commented May 26, 2017

Landed in 19685ea.

@lpinca lpinca closed this May 26, 2017
lpinca pushed a commit that referenced this pull request May 26, 2017
Refactored the `unescapeBuffer` function in order to simplify it,
and also to improve the performance.

PR-URL: #12525
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
jasnell pushed a commit that referenced this pull request May 28, 2017
Refactored the `unescapeBuffer` function in order to simplify it,
and also to improve the performance.

PR-URL: #12525
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
@jasnell jasnell mentioned this pull request May 28, 2017
@gibfahn gibfahn mentioned this pull request Jun 15, 2017
3 tasks
@MylesBorins MylesBorins added baking-for-lts PRs that need to wait before landing in a LTS release. lts-watch-v6.x labels Jul 17, 2017
@MylesBorins
Copy link
Contributor

should this land in LTS? If so it will need to bake a bit longer.

Please change labels as appropriate

@MylesBorins MylesBorins removed the baking-for-lts PRs that need to wait before landing in a LTS release. label Aug 17, 2018
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. querystring Issues and PRs related to the built-in querystring module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants