Skip to content
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

child_process.spawn execution is significantly slower than running command directly from shell #7652

Closed
yesenarman opened this issue Jul 11, 2016 · 3 comments
Labels
child_process Issues and PRs related to the child_process subsystem. performance Issues and PRs related to the performance of Node.js.

Comments

@yesenarman
Copy link

This issue came up in Glavin001/atom-beautify#893.
I have made a minimal test case for the issue: phpcbf_spawn_test.zip, but it requires you to have phpcbf from PHP-Code-Sniffer installed on your system.

The problem is, I want to execute phpcbf command with some parameters.
When doing it directly from shell it runs in under 1 second:

> phpcbf --no-patch --standard=PSR2 test.php
Changing into directory /home/arman/phpcbf_spawn_test
Processing test.php [PHP => 18 tokens in 6 lines]... DONE in 3ms (0 fixable violations)
Fixed 0 files
Time: 49ms; Memory: 4Mb

When doing it in node via child_process.spawn it takes about 1 minute:

> node beautify.js
stdout: Changing into directory /home/arman/phpcbf_spawn_test
Processing test.php [PHP => 18 tokens in 6 lines]... DONE in 2ms (0 fixable violations)
Fixed 0 files
Time: 1 mins, 0.13 secs; Memory: 4Mb


child process exited with code 1

Note that the file test.php is minimal, it shouldn't take much time to process it.

  • Version: 6.2.1 on Linux & 6.3.0 on Mac
  • Platform: Linux 3.10.0-123.8.1.el7.x86_64 & Darwin 15.5.0 (OS X 10.11.5)
  • If it might be useful my php versions are: 7.0.7 on Linux & 7.0.8 on Mac
@addaleax addaleax added performance Issues and PRs related to the performance of Node.js. child_process Issues and PRs related to the child_process subsystem. unconfirmed labels Jul 11, 2016
@addaleax
Copy link
Member

I’m 99 % sure the issue here is reported at squizlabs/PHP_CodeSniffer#993, and is not actually a bug in Node.js.

You should be able to work around that for now by adding a s.stdin.end(); line to your test script, let me know if that works.

@yesenarman
Copy link
Author

@addaleax you're right! Adding s.stdin.end(); solves the issue.

I'm sorry it didn't even come to my mind to search for an issue in phpcs.

Thank you!

@filipef101
Copy link

Hey, what could be the equivalent for a python script? Sorry for reviving this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants