Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

path: refactor normalizeArray() - improve performance #8724

Closed
wants to merge 1 commit into from

Conversation

nwoltman
Copy link

Improves performance of path.normalize() and path.resolve() (up to 3x faster in some cases).
#8342 didn't look like anyone was paying attention to it anymore so I came up with a solution that addresses @trevnorris's issue with it.

I used @dead-horse's same test code to obtain the following benchmarks:

Test Original dead-horse This PR
normalize simple path 353 ms 351 ms 335 ms
resolve simple path 1709 ms 920 ms 910 ms
normalize path contains . 885 ms 388 ms 357 ms
resolve path contains . 2653 ms 1000 ms 975 ms
normalize path contains .. 1186 ms 553 ms 370 ms
resolve path contains .. 2973 ms 1223 ms 1017 ms

Addressing @trevnorris's issue with using Array#reverse() didn't affect the first 4 tests much but removing it seems to have improved performance on the last 2 tests.

@dead-horse
Copy link

:) didn't notice that @trevnorris reply #8342

@trevnorris
Copy link

Code looks good, but haven't tested it yet.

/cc @indutny @tjfontaine

Ping back in a week if no response.

The normalizeArray() function now avoids using the slow
Array#splice() method to improve performance and now
also filters out empty path parts.

Code that pre-filtered empty parts has been removed.
@YurySolovyov
Copy link

week passed. Ping @trevnorris :)

@nwoltman
Copy link
Author

/cc @indutny @tjfontaine

trevnorris pushed a commit that referenced this pull request Nov 26, 2014
The normalizeArray() function now avoids using the slow Array#splice()
method to improve performance and now also filters out empty path parts.

Code that pre-filtered empty parts has been removed.

PR-URL: #8724
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
@trevnorris
Copy link

Thanks. Landed in e0a0e91.

@trevnorris trevnorris closed this Nov 26, 2014
@nwoltman nwoltman deleted the path-normalize branch December 4, 2014 08:18
piscisaureus pushed a commit to piscisaureus/node2 that referenced this pull request Dec 9, 2014
The normalizeArray() function now avoids using the slow Array#splice()
method to improve performance and now also filters out empty path parts.

Code that pre-filtered empty parts has been removed.

PR-URL: nodejs/node-v0.x-archive#8724
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
piscisaureus pushed a commit to nodejs/node that referenced this pull request Dec 9, 2014
The normalizeArray() function now avoids using the slow Array#splice()
method to improve performance and now also filters out empty path parts.

Code that pre-filtered empty parts has been removed.

PR-URL: nodejs/node-v0.x-archive#8724
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants