env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

Slow: ~300ms startup penalty

Open vjpr opened this issue 3 years ago • 2 comments

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

vjpr avatar Apr 11 '22 14:04 vjpr

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

KROSF avatar Aug 21 '22 21:08 KROSF

@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: https://github.com/muchobien/env-cmd/issues/18

R-Bower avatar Oct 25 '22 16:10 R-Bower