url: improve performance of the format function#57099
url: improve performance of the format function#57099nodejs-github-bot merged 1 commit intonodejs:mainfrom
Conversation
|
Review requested:
|
64039ec to
bdd5eb4
Compare
lib/url.js
Outdated
|
|
||
| search = search.replaceAll('#', '%23'); | ||
| // Escape '#' in search. | ||
| if (search.indexOf('#') !== -1) { |
There was a problem hiding this comment.
Why didn't you use primordials here?
There was a problem hiding this comment.
Maybe I'm missing something but in this file the usage of primordials seems inconsistent now
There was a problem hiding this comment.
I didn't use primordials because I forgot one spot :) changing it now!
I had the same doubt as you, the file is using very few primordials. I will create another PR to convert the whole file to be using them as much as possible
There was a problem hiding this comment.
Ah no problem I was just curious if there was a reason :)
lib/url.js
Outdated
| search = search.replaceAll('#', '%23'); | ||
| // Escape '#' in search. | ||
| if (search.indexOf('#') !== -1) { | ||
| search = search.replace(/#/g, '%23'); |
There was a problem hiding this comment.
I guess this got slower when # exists, but looks like an ok compromise
There was a problem hiding this comment.
| search = search.replace(/#/g, '%23'); | |
| search = search.replaceAll('#', '%23'); |
There was a problem hiding this comment.
By the way this is because replaceAll has similar or better performance than a global static regexp, because it doesn't need to be compiled
To lower regexp usage I had made a PR replacing all these a while ago, so I think you can safely replace with replaceAll
There was a problem hiding this comment.
fascinating, it makes sense :) updated it with StringPrototypeReplaceAll
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57099 +/- ##
=======================================
Coverage 89.09% 89.09%
=======================================
Files 665 665
Lines 193249 193252 +3
Branches 37231 37222 -9
=======================================
+ Hits 172175 172184 +9
+ Misses 13802 13799 -3
+ Partials 7272 7269 -3
🚀 New features to boost your workflow:
|
bdd5eb4 to
247e1a2
Compare
247e1a2 to
1173315
Compare
|
@nodejs/performance can someone start a url benchmark ci? |
|
https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1657/
|
|
|
antything else needed here? |
|
can I please ask for a rerun of the CI? |
|
Landed in 723d7bb |
PR-URL: #57099 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: #57099 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
As part of my ongoing review of the
assertcodebase, I started examining thelib/url.jsfile and optimizing some straightforward code that could be further refined for better performance.Here are the benchmark results for the
benchmarks/url/url-format.jsfile:For type="slashes":
123% improvement
For type="file":
50% improvement