url: optimize path resolution with single-pass algorithm#61395
Closed
anonrig wants to merge 1 commit intonodejs:mainfrom
Closed
url: optimize path resolution with single-pass algorithm#61395anonrig wants to merge 1 commit intonodejs:mainfrom
anonrig wants to merge 1 commit intonodejs:mainfrom
Conversation
Collaborator
|
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:
|
avivkeller
reviewed
Jan 16, 2026
| * @returns {{ segments: string[], up: number, trailingSlash: boolean }} | ||
| */ | ||
| function normalizePathSegments(path, allowAboveRoot) { | ||
| if (!path) return { segments: [], up: 0, trailingSlash: false }; |
Member
There was a problem hiding this comment.
Suggested change
| 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(); |
Member
There was a problem hiding this comment.
Suggested change
| segments.pop(); | |
| ArrayPrototypePop(segments); |
| // If path ends with /, ., or .., we need a trailing slash | ||
| trailingSlash = lastSeg === '' || lastSeg === '.' || lastSeg === '..'; | ||
|
|
||
| return { segments, up, trailingSlash }; |
Member
There was a problem hiding this comment.
Suggested change
| 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) === '/') { |
Member
There was a problem hiding this comment.
Suggested change
| 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('/') : |
670d025 to
816c04a
Compare
816c04a to
baa745f
Compare
Member
Author
|
Saw at most 10-15% improvement. Not worth such large sum of code change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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