nodejs / performance

Node.js team focusing on performance
MIT License
376 stars 7 forks source link

Optimize child_process performance #138

Open mehulkar opened 10 months ago

mehulkar commented 10 months ago

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

H4ad commented 10 months ago

We already tried to optimize it once: https://github.com/nodejs/performance/issues/89

anonrig commented 10 months ago

We already tried to optimize it once: https://github.com/nodejs/performance/issues/89

There is still room for optimizations probably

isker commented 8 months ago

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.

isker commented 8 months ago

4ms is still a lot, but a lot less crazy than 20ms or 38ms 🌞.