-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
url: optimize path resolution with single-pass algorithm #61395
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
Conversation
|
Review requested:
|
ad0cf95 to
670d025
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61395 +/- ##
==========================================
+ Coverage 88.51% 88.53% +0.01%
==========================================
Files 704 704
Lines 208814 208920 +106
Branches 40316 40357 +41
==========================================
+ Hits 184840 184957 +117
+ Misses 15964 15953 -11
Partials 8010 8010
🚀 New features to boost your workflow:
|
| * @returns {{ segments: string[], up: number, trailingSlash: boolean }} | ||
| */ | ||
| function normalizePathSegments(path, allowAboveRoot) { | ||
| if (!path) return { segments: [], up: 0, trailingSlash: false }; |
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.
| if (!path) return { segments: [], up: 0, trailingSlash: false }; | |
| if (!path) { | |
| return { | |
| __proto__: null, | |
| segments: [], | |
| up: 0, | |
| trailingSlash: false, | |
| } | |
| } |
| } else if (segment === '..') { | ||
| // Parent directory | ||
| if (segments.length > 0 && segments[segments.length - 1] !== '..') { | ||
| segments.pop(); |
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.
| segments.pop(); | |
| ArrayPrototypePop(segments); |
| // If path ends with /, ., or .., we need a trailing slash | ||
| trailingSlash = lastSeg === '' || lastSeg === '.' || lastSeg === '..'; | ||
|
|
||
| return { segments, up, trailingSlash }; |
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.
| return { segments, up, trailingSlash }; | |
| return { | |
| __proto__: null, | |
| segments, | |
| up, | |
| trailingSlash, | |
| } |
| // Handle mustEndAbs - ensure path starts with / | ||
| let isAbsolute = srcPath.length > 0 && srcPath[0] === ''; | ||
| if (!isAbsolute && srcPath.length > 0 && srcPath[0] && | ||
| srcPath[0].charAt(0) === '/') { |
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.
| srcPath[0].charAt(0) === '/') { | |
| srcPath[0][0] === '/') { |
| if (result.host) { | ||
| // Remove the host from srcPath (first element) | ||
| srcPath = srcPath.length > 1 ? | ||
| ArrayPrototypeJoin(srcPath, '/').slice(result.host.length + 1).split('/') : |
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.
Primordials
670d025 to
816c04a
Compare
816c04a to
baa745f
Compare
|
Saw at most 10-15% improvement. Not worth such large sum of code change. |
Includes multiple optimizations to avoid opening multiple pull-requests.
My local benchmarks show 2x-3x improvement. Let's see what the CI says.
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1782/console