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

Slow: ~300ms startup penalty #349

Open
vjpr opened this issue Apr 11, 2022 · 2 comments
Open

Slow: ~300ms startup penalty #349

vjpr opened this issue Apr 11, 2022 · 2 comments

Comments

@vjpr
Copy link

vjpr commented Apr 11, 2022

On the latest M1 Mac:

time npm exec env-cmd node index.js

npm exec env-cmd node index.js  0.24s user 0.07s system 95% cpu 0.320 total

320ms is a lot.

a. slim down

I wonder if it can be slimmed down? A simple Node invocation takes 40ms for comparison.

time node -e "console.log('hi');"

node -e "require('http'); console.log('hi');"  0.03s user 0.01s system 94% cpu 0.040 total

The following script replicates the behavior of env-cmd and weighs 73ms which seems like the theoretical minimum startup time.

const cp = require('child_process')
const fs = require('fs')
const env = fs.readFileSync('.env', 'utf8')
console.log(env)
cp.spawnSync('node', ['./main.js'])

b. use rust
Another option is migrating to Rust I guess if the logic is too heavy. E.g. This project replaces npm with a Rust version -> https://github.com/egoist/dum

@KROSF
Copy link

KROSF commented Aug 21, 2022

@vjpr if you still need env-cmd try muchobien/env-cmd is built with go so is much faster

@R-Bower
Copy link

R-Bower commented Oct 25, 2022

@vjpr if you still need env-cmd try muchobien/env-cmd is built with go so is much faster

It's incomplete. Doesn't support all of the options that this library does. See: muchobien/env-cmd#18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants