url: refactor to use more primordials#45966
Conversation
anonrig
left a comment
There was a problem hiding this comment.
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.
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.
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.
This pull request changes more than just refactoring primordials.
There was a problem hiding this comment.
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 |
joyeecheung
left a comment
There was a problem hiding this comment.
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.