-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
url: significantly improve the performance of the url module #933
Conversation
I've been using Petka's url replacement in my apps for a while now and generally it works well. This can potentially speed up a lot of apps for free. The caveats don't sound too bad either. I admit that the fact this was not merged into node (or at least reviewed) when it was first written was quite a surprise for me. |
Is this new implementation more or less compliant with the URL Standard? How does it stack up on the URL test suite? |
@domenic The goal was not to make a new url parser, just to optimize the existing one. So it should give exactly the same result as the current url url parser - if that means some will fail there then so be it. |
perhaps we should take this in the next major semver bump? |
@mikeal that's ok with me, what branch do I pr against for major? |
@petkaantonov we're still figuring that out :) we have the same problem with a PR for improving |
I know we don't have any data (and @mikeal really wants a way to make some) but I'd be surprised if this was actually back-compat-breaking in any way. |
@domenic this thread is pretty long but I seem to remember that there is an issue with the return value not working |
@mikeal https://github.com/iojs/io.js/pull/933/files#diff-3deb3f32958bb937ae05c6f3e4abbdf5R635 |
@petkaantonov are you saying it is changed or that it would need to change? |
@mikeal It is changed in this PR as I linked |
@petkaantonov sorry, in my email that link wasn't there :) |
Yea I have a really bad habit of firing comments asap and then editing them later :P |
Is there a perf impact elsewhere from changing ._extends? |
I am not sure that changing _extend's semantics is a very good idea. It'd be better to change usages of it with URLs throughout the codebase to instead call toJSON() before passing to _extends. |
@domenic what do you mean by "throughout the codebase?" the real issue isn't usage in core but usage by applications. |
I'm talking purely about _extends here. I agree that in general people will use xtend or similar tools with URLs and this change will break that, which means overall its semver-major. I just am nitpicking @petkaantonov's particular mitigating strategy for handling core. |
I cannot find a benchmark but I would be surprised if a property lookup and type-check would even show up considering the code on the very next line loads all properties of the object in an array. |
@domenic I did it this way because util._extends is essentially used as public method I think. |
@petkaantonov yes and I think modifying its behavior in the face of toJSON-able objects is not a good change to make. |
Well it could always be a hardcoded check for Url instance as well, but I was thinking that if you really defined a toJSON method on an object, you would prefer to use the properties returned by that when using ._extend. |
f7de4dc
to
4987dd1
Compare
The assertion made an assumption that the IPv6 address would always be `::1`. Since the address can be different on different platforms, it has been changed to allow multiple addresses. Fixes: nodejs#1527 PR-URL: nodejs#1531 Reviewed-By: Rod Vagg <[email protected]>
parallel tests still not working on most build slaves PR-URL: nodejs#1544 Reviewed-By: Johan Bergström <[email protected]>
@petkaantonov what's the status of this? Are you OK with @domenic's suggestion of putting getters & setters on all properties for consistency? If so, can we go ahead and get this merged or is there something else holding it up? |
@rvagg Yes I am OK with it. I just haven't gotten around to do the work. |
@petkaantonov cool, no problems, just let us know if timing sucks too much and we can cut it from 2.0.0 to take the pressure off. |
Ill work on this today and see if I can finish this |
PR-URL: nodejs#1535 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Julian Duque <[email protected]>
Some modules are monkey-patching Buffer.isEncoding, so without this they cannot do that. Fixes: nodejs#1547 PR-URL: nodejs#1548 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
PR-URL: nodejs#1473 Reviewed-By: Brendan Ashworth <[email protected]>
PR-URL: nodejs#1498 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
Making everything accessors has given some unexpected trouble with the |
This commit makes `os.tmpdir()` behave consistently on all platforms. It changes `os.tmpdir()` to always return a path without trailing slash. Semver: major Fixes: nodejs#715 PR-URL: nodejs#747 Reviewed-By: Ben Noordhuis <[email protected]>
This commit applies some secondary changes in order to make `make test` pass cleanly: * disable broken postmortem debugging in common.gypi * drop obsolete strict mode test in parallel/test-repl * drop obsolete test parallel/test-v8-features PR-URL: nodejs#1232 Reviewed-By: Fedor Indutny <[email protected]>
Cherry-pick https://codereview.chromium.org/1033733003 from upstream and re-enable postmortem debugging. PR-URL: nodejs#1232 Reviewed-By: Fedor Indutny <[email protected]>
This includes the out-of-tree patch (but fixed in upstream HEAD) from commit 41c00a2 ("deps: enable v8 postmortem debugging again".) PR-URL: nodejs#1399 Reviewed-By: Fedor Indutny <[email protected]>
This commit applies a secondary change in order to make `make test` pass cleanly, specifically re-disabling post-mortem debugging in common.gypi. PR-URL: nodejs#1506 Reviewed-By: Ben Noordhuis <[email protected]>
Cherry-pick https://codereview.chromium.org/1033733003 from upstream and re-enable postmortem debugging. PR-URL: nodejs#1232 Reviewed-By: Fedor Indutny <[email protected]>
PR-URL: nodejs#1553 Reviewed-By: Colin Ihrig <[email protected]>
Based on tests running on original Raspberry Pi PR-URL: nodejs#1554 Reviewed-By: Roman Reiss <[email protected]>
15a5c25
to
bf07d13
Compare
Moved to #1561 which is rebased against master so that it's possible to review it |
See issues: #643, nodejs/node-v0.x-archive#6788
Original message:
I have rewritten the url parser module of node core as it was/is a serious bottleneck in some of the techempower benchmarks
Running node's urlparser benchmark using iojs it's still 16x faster when not retrieving properties and 11x faster when retrieving all properties (which are lazy getters in my implementation). In absolute terms the current iojs urlparser throughputs 25k parses per second vs 400k lazy/270k eager parses per second.
format
andresolve
are also affected in similar magnitudes.Testing this PR on my VM ubuntu I get
After
Before
That's 10-24x faster depending on url.
Caveats
This implementation uses getters/setters on the prototype instead of own properties like current url. This is because often the properties are not needed and take time to calculate. Additionally @chrisdickinson introduced another reason to use setters at #893 (comment).
This patch is technically backward incompatible but to minimize any compatibility issues I made
util._extend
to calltoJSON
, because some core modules pass the Url instance directly toutil._extend
. ThetoJSON
also means that serialized output of current url and the new url stay the same./cc @trevnorris @mikeal