-
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: improve url.parse() performance #4892
Conversation
FWIW here is the output from the url-parse benchmark:
|
Is this related to #2303? |
5e612b4
to
521927b
Compare
@silverwind I hadn't seen that PR before this. However, trying that other PR (just This PR passes the existing tests and diverges less from the original code (FWIW). |
I made the |
LGTM if CI is green |
Marking this as lts-watch but I definitely think we need to wait to land until after it goes out in a stable for a few weeks. |
1f2ac71
to
c492001
Compare
uh... cc @domenic maybe? |
Hrmm, somehow the CI job got lost. Here it is again: https://ci.nodejs.org/job/node-test-pull-request/1463/ |
CI looks good, but might be worth getting a citgm run on this. /cc @thealphanerd |
let srcPath = result.pathname && result.pathname.split('/') || []; | ||
const relPath = relative.pathname && relative.pathname.split('/') || []; | ||
var srcPath = result.pathname && result.pathname.split('/') || []; | ||
var relPath = relative.pathname && relative.pathname.split('/') || []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: Did var
turn out to be faster than the scoped variants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The resolveObject()
changes were mostly unintentional as the url
module was modified while I was working on this. However, the reverting of let
is intentional as let
is still slow in v8. I've left the const
as-is though.
This commit improves url.parse() performance by 50-210% with the existing url/url-parse benchmarks. Also, the optimizations made in url.format() result in a 40% increase in performance for url.resolve(). Some optimization strategies used in this commit include: * Combining multiple searches on the same string into a single loop * Avoiding unnecessary string.split() and array.join() * Minimizing creation of temporary strings * Using a faster alternative to encodeURIComponent, borrowed from the querystring module
c492001
to
37c3051
Compare
citgm: https://ci.nodejs.org/job/thealphanerd-smoker/62/ note: run with this patched node https://github.com/TheAlphaNerd/node/tree/improve-url-parse |
Looking at the citgm results the only non-flaky error result is the |
/cc @nodejs/collaborators Any other comments/LGTMs for this? As far as the other url performance PRs go, I'm not opposed to them if they improve performance even more than this PR. However this PR already passes all tests and is more conservative since it preserves the original |
LGTM, but I haven't looked at any of the other PRs. |
I'm LGTM as well -- I get the impression that the other PR needs more work/review; hopefully will land at a later stage. |
So, I propose we get this in asap, and possibly backport to LTS. |
These major perf rewrites are not great candidates for LTS cause of their higher risk of finding edge-cases that we won't otherwise find. We improve the chances with letting them bake in v5 for a while but it doesn't make the risk disappear completely. As it stands I'm -1 on this for v4 unless someone wants to make a case that it's not as major as it looks. |
This commit improves url.parse() performance by 50-210% with the existing url/url-parse benchmarks. Also, the optimizations made in url.format() result in a 40% increase in performance for url.resolve(). Some optimization strategies used in this commit include: * Combining multiple searches on the same string into a single loop * Avoiding unnecessary string.split() and array.join() * Minimizing creation of temporary strings * Using a faster alternative to encodeURIComponent, borrowed from the querystring module PR-URL: #4892 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ryan Graham <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
Landed in db91281. |
I'm with @rvagg here. I think in general we could be too frisky with backports -- I prefer the more anal "bugfixes only" to avoid corner cases. |
performance is a feature |
👍 Never know what could be broken months down the line. Glad to see this merged regardless for 5+. |
It looks like this was landed three weeks after its last CI run happened. In the intervening time, new lint rules were added. So now |
This commit improves url.parse() performance by 50-210% with the existing url/url-parse benchmarks. Also, the optimizations made in url.format() result in a 40% increase in performance for url.resolve(). Some optimization strategies used in this commit include: * Combining multiple searches on the same string into a single loop * Avoiding unnecessary string.split() and array.join() * Minimizing creation of temporary strings * Using a faster alternative to encodeURIComponent, borrowed from the querystring module PR-URL: #4892 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ryan Graham <[email protected]> Reviewed-By: Johan Bergström <[email protected]>
Related issue: |
@nodejs/lts this commit introduced some regressions, there are fixes coming in or already in I believe. Is this something we will want to back port if we have the fixes and it has been stable for a bit? Part of me want to just say don't land, and avoid potential regressions... but this is some pretty major churn. |
@thealphanerd I would delay a while. Same with my timers thing. |
@thealphanerd ... I'm going to say hold off for now. There are too many regressions on this. Even with the fixes coming this should sit for a while in master and v5 before we pull it back to v4. |
In fact, let's take the lts-watch label off and put the don't land in v4 label on. We can revisit later once we're sure things are stable and the regressions are handled. |
I'm a strong -1 on putting this or similar performance commits on to LTS, for simple and clearly low-risk commits we can consider on a case-by-case basis but these introduce too much variability into LTS which we are committed to keeping stable. It's important we achieve and maintain trust with users and give them zero reason to fear upgrading from release to release. |
Agree. While I'd love to get performance improvements into LTS in general if possible, these kinds of changes are far too invasive, I think, and open too many possible risks for LTS. Unfortunately, however, not landing them could make cherrypicking more difficult later but we knew that going in. |
If this does come it needs to land with #5300 |
Just noting #5300 has been landed. |
@benjamingr I think @thealphanerd meant if it landed on v4.x. |
Oh, I saw that the lts-watch has been removed, reading it again it looks like it isn't landing on 4.x either. Sorry. |
This commit improves
url.parse()
performance by 50-200% with the existing url/url-parse benchmarks. Also, the optimizations made inurl.format()
result in a 40% increase in performance forurl.resolve()
.Some optimization strategies used in this commit include:
single loop
string.split()
andarray.join()
borrowed from the
querystring
module