deps: improve macOS spawn PATH performance - #66005
Conversation
|
Review requested:
|
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
|
Note the dependencies documentation section of the Pull requests guide:
|
Signed-off-by: splincode <omaxphp@yandex.ru>
dfc7d0e to
3d86f80
Compare
|
Thanks for pointing this out. I moved the change upstream to libuv: Closing this PR as the dependency update should come through libuv. |
Refs: #62554
Summary
On macOS, resolving a child process executable through
PATHcurrently requires libuv to manually walk everyPATHentry and callposix_spawn()for each candidate.For commands such as:
this can result in multiple failed
posix_spawn()calls before the executable is found, making process spawning noticeably slower with longerPATHvalues.This change restores a
posix_spawnp()fast path for the common case where it is safe to use.Why this is safe
libuv previously stopped using
posix_spawnp()on macOS because of a macOS bug involvingposix_spawn_file_actions_addchdir_np().The fast path added here is only used when:
cwdchange is requested;PATHis identical to the parent processPATH.This means
posix_spawnp()resolves the same executable as the current manual implementation, while avoiding the macOScwdissue.Calls using a custom
PATHorcwdcontinue to use the existing manual resolution path.Benchmark
A new
child_processbenchmark compares PATH-based executable lookup with an absolute path while varying the number of PATH entries.The benchmark covers:
Notes
The regression reported in #62554 is macOS-specific, so performance results should be collected on macOS before this is considered ready to land.
This change modifies the vendored libuv implementation. If this should be contributed to
libuv/libuvfirst instead, I am happy to move the fix upstream there.