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: avoid indexOf when parsing #14703

Closed
wants to merge 1 commit into from
Closed

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Aug 8, 2017

Fixes a performance regression in body-parser with V8 6.0.
Removes the use of an auxiliary array, and just query the object
directly.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

querystring

Fixes a performance regression in body-parser with V8 6.0.
Removes the use of an auxiliary array, and just query the object
directly.
@nodejs-github-bot nodejs-github-bot added the querystring Issues and PRs related to the built-in querystring module. label Aug 8, 2017
@MylesBorins
Copy link
Contributor

MylesBorins commented Aug 8, 2017

Copy link
Contributor

@evanlucas evanlucas left a comment

Choose a reason for hiding this comment

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

LGTM. The body-parser test suite is significantly faster with this change

@mcollina
Copy link
Member Author

mcollina commented Aug 8, 2017

We should probably add a benchmark/unit test to check that we do not regress on this.

Here is what I have used: https://gist.github.com/mcollina/f76e8ad685db1686a49aceee66daf075.

Feel free to push on this branch and land, I will not have time in the next few days.

@mscdex
Copy link
Contributor

mscdex commented Aug 8, 2017

In general it looks fine to me since Object.create(null) is fast enough now and using that would mean we wouldn't have to check for an 'own property' anymore, but we definitely should have some good benchmark(s) for this that are ran before landing just in case.

@TimothyGu
Copy link
Member

@mcollina Can you post the benchmark results, just for good measure?

@mcollina
Copy link
Member Author

mcollina commented Aug 9, 2017

I'm on vacation until next Wednesday. I guess we might want to land this sooner, could someone else take the lead and run the benchmarks?

@TimothyGu
Copy link
Member

To clarify I'm more than fine with this being landed before performance results are available, just wondering :)

@MylesBorins
Copy link
Contributor

The body parser suite completely fails on all platforms without this change.

I would like to see this landed before we have benchmarks, it is blocking the release of 8.3.0

@mcollina
Copy link
Member Author

mcollina commented Aug 9, 2017

I am +1 in landing as is and getting 8.3.0 out.

@evanlucas
Copy link
Contributor

+1 to landing this now and getting 8.3.0 out as well. I ran the benchmarks yesterday and the results were pretty varied for all but the manypairs filter in querystring-parse. It was ~25% faster with this change. The others fluctuated and I haven't had a chance to run without anything else running locally

@MylesBorins
Copy link
Contributor

If I don't see any complaints I will land this on master in exactly 2 hours

@addaleax
Copy link
Member

addaleax commented Aug 9, 2017

With n set to 1e5 instead of 1e6, to get benchmark results in a reasonable time:

$ ./node benchmark/compare.js --new ./node --old ./node-master --runs 20 --filter parse querystring | Rscript benchmark/compare.R
[00:05:25|% 100| 1/1 files | 40/40 runs | 10/10 configs]: Done
                                                                  improvement confidence      p.value
 querystring/querystring-parse.js n=100000 type="altspaces"          -6.37 %        *** 1.480084e-11
 querystring/querystring-parse.js n=100000 type="encodefake"         -5.67 %        *** 6.231106e-07
 querystring/querystring-parse.js n=100000 type="encodelast"         -7.49 %        *** 1.104349e-08
 querystring/querystring-parse.js n=100000 type="encodemany"         -3.09 %         ** 3.595906e-03
 querystring/querystring-parse.js n=100000 type="manyblankpairs"      2.28 %        *** 1.031729e-04
 querystring/querystring-parse.js n=100000 type="manypairs"          19.22 %        *** 7.423575e-28
 querystring/querystring-parse.js n=100000 type="multicharsep"       -8.20 %        *** 2.022304e-10
 querystring/querystring-parse.js n=100000 type="multivalue"          0.86 %            4.507649e-01
 querystring/querystring-parse.js n=100000 type="multivaluemany"     15.06 %        *** 1.043772e-12
 querystring/querystring-parse.js n=100000 type="noencode"           -6.47 %        *** 1.616370e-08

@MylesBorins
Copy link
Contributor

@addaleax do you think it is ok to land?

@addaleax
Copy link
Member

addaleax commented Aug 9, 2017

@MylesBorins Yes, I think so. If you do that now, I can take care of updating the v8.3.0 proposal.

@MylesBorins
Copy link
Contributor

landed in 7ec28a0

@MylesBorins MylesBorins closed this Aug 9, 2017
MylesBorins pushed a commit that referenced this pull request Aug 9, 2017
Fixes a performance regression in body-parser with V8 6.0.
Removes the use of an auxiliary array, and just query the object
directly.

PR-URL: #14703
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
addaleax pushed a commit that referenced this pull request Aug 9, 2017
Fixes a performance regression in body-parser with V8 6.0.
Removes the use of an auxiliary array, and just query the object
directly.

PR-URL: #14703
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
querystring Issues and PRs related to the built-in querystring module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.