-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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: use primordials in url.js #54489
base: main
Are you sure you want to change the base?
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.
nice!
protocol[0] === 'f' && | ||
protocol[1] === 'i' && | ||
protocol[2] === 'l' && | ||
protocol[3] === 'e') { |
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.
should this use your new isFileProtocol
helper?
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.
no because isFileProtocol is also accepting ':' at the end of the string but here according to the comment it is about adding ':' at the end of the protocol if it is missing.
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 guess you could use it after the length check
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.
for performance reasons, i think this is better
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #54489 +/- ##
==========================================
+ Coverage 87.31% 87.34% +0.02%
==========================================
Files 648 649 +1
Lines 182359 182543 +184
Branches 34979 35038 +59
==========================================
+ Hits 159235 159438 +203
+ Misses 16389 16373 -16
+ Partials 6735 6732 -3
|
You probably meant another PR, I doubt this is a follow up from the release proposal. |
Sry, I meant #54486 |
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.
This hasn't been a problem for a really long time. Why are we adding more primordials to this?
because ljharb wrote that they make kind of sense. I personally would like to provide just a PR with performance optimizations, where i basically reduce the amount of used primordials/fuunction calls. |
to be clear, I didn’t suggest making changes - i just said that they always are a good idea for a robust platform in response to your question. |
Nope, my question was regarding that special case where function isIpv6Hostname(hostname) {
return (
StringPrototypeCharCodeAt(hostname, 0) === CHAR_LEFT_SQUARE_BRACKET &&
StringPrototypeCharCodeAt(hostname, hostname.length - 1) ===
CHAR_RIGHT_SQUARE_BRACKET
);
} could be replaced with function isIpv6Hostname(hostname) {
return (
hostname[0] === '[' &&
hostname[hostname.length - 1] === ']'
);
} thus avoiding primordials completely. And you answered, that primordials are always better. |
Anyhow. How about reverting those primordials stuff and just focus on the performance improvements? |
I think you misunderstood me then. I said that primordials are always better than instance methods. Obviously it's better to avoid the methods entirely if you can. |
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 don't think we should do it. There is no particular reason to pursue more primordials for url
right now.
Follow up to #54486
@ljharb wrote
The funny part is that in url.js are many many non primordial function calls.And my question regarding the primordials was regarding my specific example about replacing
.charCodeAt(0)
with direct accessing the character of a string via index[0]
.I refactored it basically to use primordials, when it makes sense.
So e.g.
value.slice(i)
was transformed toStringPrototypeSlice(value, i)
butvalue.charCodeAt(0) === 58/* : */)
was transformed tovalue[0] === ':'
, as it makes no sense to me to useStringPrototypeCharCodeAt
.Maybe some method calls are not transformed, which can be changed of course. I did it manually and tbh. I wanted your feedback before I continue to work on this. If you absolutely reject it in principal, than why should I invest more time anyway.
I did not bench it. Maybe somebody can run the benchmarks on the benchmark machine?