path: remove StringPrototypeCharCodeAt from more posix methods - #63662
path: remove StringPrototypeCharCodeAt from more posix methods#63662whoekage wants to merge 1 commit into
Conversation
|
Review requested:
|
|
Hi! Could a collaborator start CI here when convenient? The change is small This extends the same Related C++ path optimization: #63753. Thanks! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
@whoekage Can you sign your commit and force push? It's required as per updated instructions
|
Extends the optimization applied to posix.extname in nodejs#54546 to posix.dirname, posix.basename, and posix.relative. nodejs#54668 covers posix.resolve, posix.normalize, and posix.parse. Replacing `StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASH` with `path[i] === '/'` is consistently faster on V8 because the single-character string comparison hits a faster path than the integer comparison after charCodeAt(). Benchmark (Apple M1, 30 runs via benchmark/compare.js): dirname-posix: path='/foo' +12.45% *** path='/foo/bar/baz/asdf/quux' +8.82% *** path='/foo/bar' +8.82% *** path='foo' +6.34% * path='foo/bar' +2.26% * basename-posix: pathext='/foo/bar/baz/asdf/quux.html|.html' +8.38% *** pathext='/foo/.bar.baz|.baz' +8.25% *** pathext='/foo/.bar.baz' +6.90% *** pathext='foo/bar.' +5.94% *** pathext='foo' +5.78% * relative-posix: paths='/var|/bin' +3.28% ** No regressions in Win32 paths (slow path untouched). Control benchmark on extname (unchanged) shows ±2% noise without significance, confirming methodology. Signed-off-by: sharkaev.ph <sharkaev.ph@gmail.com>
5523055 to
3b3bb25
Compare
|
@trivikr Done. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Summary
Extends the optimization landed in #54546 (
posix.extname) to the remaining POSIX path methods still usingStringPrototypeCharCodeAt. #54668 coversresolve/normalize/parse; this PR coversdirname,basename, andrelative.What changed
Replaced
StringPrototypeCharCodeAt(path, i) === CHAR_FORWARD_SLASHwithpath[i] === '/'in three POSIX methods. Diff: +12 / −14 lines inlib/path.js.Benchmark
Apple M1, 30 runs via
benchmark/compare.js. Showing significant cases:dirname-posix
/foo/foo/bar/baz/asdf/quux/foo/barfoofoo/barbasename-posix
/foo/bar/baz/asdf/quux.html|.html/foo/.bar.baz|.baz/foo/.bar.bazfoo/bar.foorelative-posix
/var|/binMethodology 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
parallel/test-path*— all 17 passparallel/test-url-*— all 15 passparallel/test-fs-readfile/stat/realpath— passparallel/test-module-*— all 32 passmake lint-js— cleanRefs: #54546, #54668