New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Node's native spawnSync for execSync to improve performance #758
Conversation
Codecov Report
@@ Coverage Diff @@
## master #758 +/- ##
==========================================
- Coverage 97.38% 97.33% -0.06%
==========================================
Files 33 33
Lines 1222 1199 -23
==========================================
- Hits 1190 1167 -23
Misses 32 32
Continue to review full report at Codecov.
|
src/exec.js
Outdated
var stdout = fs.readFileSync(stdoutFile, 'utf8'); | ||
var stderr = fs.readFileSync(stderrFile, 'utf8'); | ||
stdout = c.stdout || ''; | ||
stderr = c.stderr || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the problem: with stdio: 'inherit'
, c.stdout
and c.stderr
are both null
. However, we need to be able to return stdout
and stderr
from the call to exec
, as that is part of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, you're right. I didn't realize this. It's fixed now.
Btw. I noticed strange behavior. If you run an interactive command with exec
, eg. git commit
(with vim
configured as an EDITOR
) previous version of execSync
will end up in not so functional state, you have to basically end up the script with Ctrl+C.
The current version just print out something like this:
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal
Vim: Error reading input, exiting...
Vim: Finished.
error: There was a problem with the editor 'nvim'.
Please supply the message using either -m or -F option.
I haven't reviewed this carefully, but this will almost certainly break behavior (which is why I was going to write an alternative to Potential issues I can think of off the top of my head:
|
@nfischer I tested both cases and they seem to be working correctly. I also added test for the first case. I checked your PR with |
@nfischer Oh, sorry, I was too eager… The newly added test failed on Node v8 (I run node 6.11 locally)… Hmm, ok, not sure about my "fix" then… |
I overlooked that appveyor runs tests on Windows. It probably should pass even on Windows? The test wasn't here before so I'm not sure about the previous version of |
Thanks for checking. It looks like we see different behavior for Windows and Unix for Also, how does this handle output? |
@nfischer Unfortunately real time output is not implemented. I've been playing with it for a while but I cannot figure out any solution. Surprisingly it leads to the original solution of I think now… the bottleneck of the original solution, IMO, is that for every command there is spawned node process and several files are created. What if this node process and files are created only once for the first |
There are some potential wins here. I think (but we should verify) that Process creation should happen lazily on the first Without lots of effort, we may be able to remove the exit code file and just use the process return status (which I think We can rearchitect things a bit like in #524. Right now we write an entire script to a temp file, but we can move this to a new source file and pass parameters in via Is there a way to do IPC without writing to the file system? That would be ideal, but I've yet to find a way. |
@nfischer After quick research I found that IPC uses sockets, it can work with unix sockets, TCP, UDP etc. But I think this idea won't work because IPC is completely async. I think we can close this PR without merge as I don't know how to fix it. And if you say Anyway, thanks for your support and time on this. |
I won't continue on this PR => closed. |
Hello,
I tried to rewrite
execSync
method with usage of Node's nativespawnSync
as it should improve performance of sync version ofshell.exec
method rapidly.According to my own test script the improvement is from original 12s to 1.6s after change.
What do you think?
I had to remove one test and I hope it works the same way as before. I don't have a Windows machine so it would be great to confirm it works the same also under Windows.
Btw. it could also fix following issues: