-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
esm: avoid try/catch when validating urls #47541
esm: avoid try/catch when validating urls #47541
Conversation
Review requested:
|
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.
Given that URL.canParse
is user-mutable, should we use const { canParse } = URL
or something like that? Or even better, can we import it primordial-style from ada directly?
@aduh95 I like where this is going, but I couldn't visualize it. Can you elaborate on how we can import it primordial-style? We can always do |
Yes, I mean something that's available only internally and cannot be mutated at runtime. |
5375959
to
3a57762
Compare
This is way better/cleaner :-) but does it prevent backporting this commit, since older release lines may not have URL.canParse? |
It might make it harder, due to conflicts, but I don't think it will block backporting any future changes to ESM. |
oh sure, i just meant, should this PR have any "do not backport" labels, or link to the canParse PR as a prereq? |
I'm not quite sure. @nodejs/releasers what do you recommend? |
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.
Sweet, thanks! I was just suggesting this change last night in Slack 😁
|
I'm confused by this. The C++ API still says this: Lines 116 to 117 in 4afb25c
Or did you actually mean this PR does not improve performance until the TODO is resolved? |
I was giving some context to this particular change. It is definitely faster than the current implementation. Additionally, @KhafraDev just opened a pull request for adding v8 fast API to |
@aduh95 perfect, thanks for clarifying and linking :-) |
3a57762
to
05742e9
Compare
Would someone re-review this pull request? It's required due to force-push. |
@@ -35,6 +35,7 @@ const { | |||
} = require('internal/errors').codes; | |||
const { exitCodes: { kUnfinishedTopLevelAwait } } = internalBinding('errors'); | |||
const { URL } = require('internal/url'); | |||
const { canParse: urlCanParse } = internalBinding('url'); |
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.
nit: this sounds a little Yoda-esque
const { canParse: urlCanParse } = internalBinding('url'); | |
const { canParse: canParseURL } = internalBinding('url'); |
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.
Not sure this is better, isURLString
might be more suited. URLCanParse
has the upside of being consistent with how primordials are named, which is nice imho
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.
I want to change this to URLCanParse too but I'm too demotivated by having to run Node.js CI multiple times because of the flaky tests.
Landed in 17570c0 |
PR-URL: #47541 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
PR-URL: nodejs#47541 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
PR-URL: nodejs/node#47541 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
PR-URL: nodejs/node#47541 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Due to
URL.canParse
, we can avoid try/catch block and have faster validation. The previous implementation was not performant due to:href
,origin
etc. for validating if a URL is valid or not.URL.canParse
can be written with V8 Fast API - enabling more performance out of this pull request.URL.canParse
does not return anything except a boolean.cc @nodejs/url