-
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: refactor to use more primordials #45966
Conversation
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 pull request includes changes more than just refactoring primordial, and might confuse reviewers. I recommend either changing the title of this pull request or introducing changes other than primordials to a different pull request.
Can you also run a benchmark?
lib/internal/url.js
Outdated
if (!isWindows) filepath = StringPrototypeReplaceAll(filepath, '\\', '%5C'); | ||
filepath = StringPrototypeReplaceAll(filepath, '\n', '%0A'); | ||
filepath = StringPrototypeReplaceAll(filepath, '\r', '%0D'); | ||
filepath = StringPrototypeReplaceAll(filepath, '\t', '%09'); |
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.
According to micro-benchmarks, ReplaceAll
is slower than Replace
. I prefer using the existing implementation. Referencing: https://github.com/RafaelGSS/nodejs-bench-operations/blob/main/RESULTS-v19.md
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 existing implementation relies on user-mutable RegExp.prototype[Symbol.replace]
. According to my own research, replaceAll
on a string was faster than building a robust regex. (Actually in this case we're reusing the same regex, so it should not really matter, let's go with the regex approach)
lib/internal/url.js
Outdated
outURL.hostname = domainToASCII(hostname); | ||
outURL.pathname = encodePathChars( | ||
ArrayPrototypeJoin(ArrayPrototypeSlice(paths, 3), '/')); | ||
StringPrototypeReplaceAll(StringPrototypeSlice(filepath, hostnameEndIndex), '\\', '/')); |
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 pull request changes more than just refactoring primordials.
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.
StringPrototypeSplit
relies on user-mutable String.prototype[Symbol.split]
, so it's not exactly unrelated.
FYI that's why I added
needs-benchmark-ci
|
This comment was marked as outdated.
This comment was marked as outdated.
0008c09
to
b2ab16c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Do we actually have benchmarks for |
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.
We need to benchmark url.fileURLToPath()
and url.pathToFileURL()
, they are used a lot internally and are affected by this PR
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
1de5314
to
b8d193f
Compare
Landed in e487638 |
PR-URL: #45966 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #45966 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
PR-URL: #45966 Reviewed-By: Zeyu "Alex" Yang <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
No description provided.