Skip to content

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Jan 15, 2026

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

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. url Issues and PRs related to the legacy built-in url module. labels Jan 15, 2026
@anonrig anonrig force-pushed the yagiz/optimize-url branch from ad0cf95 to 670d025 Compare January 15, 2026 22:25
@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.52%. Comparing base (538aebf) to head (670d025).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #61395    +/-   ##
========================================
  Coverage   88.51%   88.52%            
========================================
  Files         704      704            
  Lines      208814   208927   +113     
  Branches    40316    40343    +27     
========================================
+ Hits       184840   184954   +114     
- Misses      15964    15965     +1     
+ Partials     8010     8008     -2     
Files with missing lines Coverage Δ
lib/url.js 100.00% <100.00%> (ø)

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* @returns {{ segments: string[], up: number, trailingSlash: boolean }}
*/
function normalizePathSegments(path, allowAboveRoot) {
if (!path) return { segments: [], up: 0, trailingSlash: false };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
segments.pop();
ArrayPrototypePop(segments);

// If path ends with /, ., or .., we need a trailing slash
trailingSlash = lastSeg === '' || lastSeg === '.' || lastSeg === '..';

return { segments, up, trailingSlash };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) === '/') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('/') :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primordials

@avivkeller avivkeller added the needs-benchmark-ci PR that need a benchmark CI run. label Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. url Issues and PRs related to the legacy built-in url module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants