Skip to content

path: skip normalize for already-normalized paths - #66177

Open
anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/path-normalize-fast-ead2
Open

anonrig wants to merge 1 commit into
nodejs:mainfrom
anonrig:cursor/path-normalize-fast-ead2

Conversation

@anonrig

@anonrig anonrig commented Sep 21, 2026

Copy link
Copy Markdown
Member

If a posix path contains no '.' and no '//', it has no '.'/'..' segments and no empty segments, so path.posix.normalize() can return the input without running normalizeString().

This change was implemented with assistance from a closed-source coding agent. I verified the source, official benchmark/path/normalize-posix.js results, and test-path-normalize.js.

Official benches

Three-run medians, n=1e5:

path main this PR delta
/foo/bar 8.4M 13.9M +66%
/foo 11.6M 15.2M +31%
/foo/bar//baz/asdf/quux/.. 3.13M 2.95M −6%

Already-normalized paths (the common case) skip the segment walk. Paths that still need normalizeString() pay two indexOf probes.

Tests

test-path-normalize.js, test-path.js, test-path-join.js, test-path-resolve.js.

If a posix path contains no '.' and no '//', it has no '.'/'..'
segments and no empty segments, so the result is the input.

Official benchmark/path/normalize-posix.js:
/foo/bar is about 66% faster and /foo is about 31% faster.
Paths that still need normalizeString are slightly slower
because of the two indexOf probes.

Assisted-by: a closed-source coding agent
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/path

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. path Issues and PRs related to the path subsystem. labels Sep 21, 2026
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.28%. Comparing base (dd5dfb5) to head (f969fe6).
⚠️ Report is 41 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66177      +/-   ##
==========================================
+ Coverage   90.27%   90.28%   +0.01%     
==========================================
  Files         790      790              
  Lines      271651   272049     +398     
  Branches    51842    51949     +107     
==========================================
+ Hits       245228   245618     +390     
- Misses      16928    16934       +6     
- Partials     9495     9497       +2     
Files with missing lines Coverage Δ
lib/path.js 97.49% <100.00%> (+<0.01%) ⬆️

... and 61 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. path Issues and PRs related to the path subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants