Tyrrrz / CliWrap

Library for running command-line processes
MIT License
4.36k stars 268 forks source link

Remove setting of `CreateNoWindow` to reduce overhead #142

Closed ian-g-holm-intel closed 2 years ago

ian-g-holm-intel commented 2 years ago

I've observed a 30-40ms overhead added to the execution time of any process when you set ProcessStartInfo.CreateNoWindow to anything, true or false. I'm not sure why exactly this is, but you can see the difference in the benchmarks really easily. CliWrap sets CreateNoWindow = true and UseShellExecute = false. But as far as I can tell, UseShellExecute = false is the default and CreateNoWindow doesn't work unless UseShellExecute = true. So removing those two settings from the ProcessStartInfo is functionally equivalent to the way they are currently, but it allows processes to run without the 30ms overhead.

ian-g-holm-intel commented 2 years ago

I ran a benchmark executing "cmd.exe /c echo this is a test" with CreateNoWindow set to true vs unset. CreateNoWindow = true before CreateNoWindow unset after

ian-g-holm-intel commented 2 years ago

This proposed fix will check if the current application has a console or not. If it does not, it will set ProcessStartInfo.CreateNoWindow = true. If it does have a console, CreateNoWindow will not be set, avoiding the added overhead of setting it.

Tyrrrz commented 2 years ago

@Retik okay, just to make sure, you tested all previously scenarios with this and it works correctly, right? desktop/console/batch file, etc

what-the-diff[bot] commented 1 year ago