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.53%. Comparing base (538aebf) to head (baa745f).
⚠️ Report is 13 commits behind head on main.

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              
Files with missing lines Coverage Δ
lib/url.js 100.00% <100.00%> (ø)

... and 39 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
@anonrig anonrig force-pushed the yagiz/optimize-url branch from 670d025 to 816c04a Compare January 16, 2026 14:12
@anonrig anonrig force-pushed the yagiz/optimize-url branch from 816c04a to baa745f Compare January 16, 2026 17:07
@anonrig anonrig closed this Jan 16, 2026
@anonrig
Copy link
Member Author

anonrig commented Jan 16, 2026

Saw at most 10-15% improvement. Not worth such large sum of code change.

@anonrig anonrig deleted the yagiz/optimize-url branch January 16, 2026 18:26
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