path: remove StringPrototypeCharCodeAt from more posix methods
Summary
Extends the optimization landed in #54546 (posix.extname) to the remaining POSIX path methods still using StringPrototypeCharCodeAt. #54668 covers resolve/normalize/parse; this PR covers dirname, basename, and relative.
What changed
Replaced StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH with path[i] === '/' in three POSIX methods. Diff: +12 / −14 lines in lib/path.js.
Benchmark
Apple M1, 30 runs via benchmark/compare.js. Showing significant cases:
dirname-posix
| path | delta | sig |
|---|---|---|
/foo |
+12.45% | *** |
/foo/bar/baz/asdf/quux |
+8.82% | *** |
/foo/bar |
+8.82% | *** |
foo |
+6.34% | * |
foo/bar |
+2.26% | * |
basename-posix
| pathext | delta | sig |
|---|---|---|
/foo/bar/baz/asdf/quux.html|.html |
+8.38% | *** |
/foo/.bar.baz|.baz |
+8.25% | *** |
/foo/.bar.baz |
+6.90% | *** |
foo/bar. |
+5.94% | *** |
foo |
+5.78% | * |
relative-posix
| paths | delta | sig |
|---|---|---|
/var|/bin |
+3.28% | ** |
Methodology validation
Control benchmark on extname-posix (unchanged in this PR) shows ±2% deltas without statistical significance, confirming methodology. No regressions on Win32 paths (slow path untouched).
Test plan
- [x]
parallel/test-path*— all 17 pass - [x]
parallel/test-url-*— all 15 pass - [x]
parallel/test-fs-readfile/stat/realpath— pass - [x]
parallel/test-module-*— all 32 pass - [x] Fuzz: 425 input cases identical to baseline
- [x]
make lint-js— clean
Refs: #54546, #54668
Review requested:
- [ ] @nodejs/path
Hi! Could a collaborator start CI here when convenient? The change is small (+12/-14) and the path tests pass locally.
This extends the same StringPrototypeCharCodeAt(...) === CHAR_* to
path[i] === '*' conversion that was already accepted in #54546 (merged,
posix.extname) and is in progress in #54668, applied to the remaining posix
methods.
Related C++ path optimization: #63753.
Thanks!
CI: https://ci.nodejs.org/job/node-test-pull-request/75118/
CI: https://ci.nodejs.org/job/node-test-pull-request/75150/
CI: https://ci.nodejs.org/job/node-test-pull-request/75680/
@whoekage Can you sign your commit and force push?
It's required as per updated instructions
Your commit must contain the Signed-off-by line with your name and email address as an acknowledgement that you agree to the Developer Certificate of Origin
@trivikr Done. Signed off and force-pushed. The diff is unchanged, only the commit message now carries the Signed-off-by line. Could you kick off a fresh CI run when you get a chance?
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 90.06%. Comparing base (79def6d) to head (3b3bb25).
:warning: Report is 1081 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #63662 +/- ##
==========================================
- Coverage 90.32% 90.06% -0.26%
==========================================
Files 732 751 +19
Lines 236435 254418 +17983
Branches 44527 47964 +3437
==========================================
+ Hits 213563 229151 +15588
- Misses 14589 16446 +1857
- Partials 8283 8821 +538
| Files with missing lines | Coverage Δ | |
|---|---|---|
| lib/path.js | 97.48% <100.00%> (-0.01%) |
:arrow_down: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1892/