Open mehulkar opened 10 months ago
We already tried to optimize it once: https://github.com/nodejs/performance/issues/89
We already tried to optimize it once: https://github.com/nodejs/performance/issues/89
There is still room for optimizations probably
child_process takes ~20ms to run a script with execSync
I don't think your benchmark is really measuring child_process spawn performance, just the overhead of launching node compared to bash. Comment out every line in the node script and see how little the timing changes. For me on macOS, the hyperfine-measured time goes from ~38ms to ~34ms.
4ms is still a lot, but a lot less crazy than 20ms or 38ms 🌞.
child_process takes ~20ms to run a script with
execSync
. If this can be optimized further, that would be great.Use case
I have ported some bash scripts to Node.js to make them more easily cross-platform. But sometimes that means using child_process to call out to other programs (e.g.
git
). These calls can add up and make me think twice about the performance tradeoff.Benchmark
Here's a benchmark: https://github.com/mehulkar/bench-childprocess
Ref