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

NVM shouldn't source a shell script to start, it's too slow #2084

Closed
mlindner opened this issue Aug 6, 2019 · 6 comments
Closed

NVM shouldn't source a shell script to start, it's too slow #2084

mlindner opened this issue Aug 6, 2019 · 6 comments
Labels
performance

Comments

@mlindner
Copy link

mlindner commented Aug 6, 2019

NVM causes way too much slowdown on terminal start because it's sourcing a shell script. It shouldn't have to do this for the NVM to work. This is in need of a full redesign of this idea. I don't know who thought that sourcing a slow shell script on shell start was a good idea.

Has no one in this project heard of lazy initialization? NVM has become an impediment to work, not a help.

@ljharb
Copy link
Member

ljharb commented Aug 6, 2019

You're incorrect; the reason there's slowdown is entirely because auto-using invokes npm config get prefix - sourcing a shell script is not slow and never has been slow.

If you source with --no-use, or if you nvm unalias default and have no .nvmrc file, you won't see any slowdown (a slowdown that only a minority of users suffer from).

Lazy initialization is simply incorrect because it wouldn't make all global npm modules available on the command line along with node and npm.

The long term solutions are either to 1) have npm get faster, or 2) have nvm reimplement the npm config get prefix logic, but somehow make it faster than npm itself.

@ljharb ljharb closed this as completed Aug 6, 2019
@ljharb ljharb added the performance label Aug 6, 2019
@kaiwk
Copy link

kaiwk commented Apr 14, 2020

If we source nvm in .bashrc, it will be sourced every time on shell starts.
If we source nvm in .bash_profile, at least for Linux, it will be sourced once when user first login.

Maybe we should export nvm functions, and encourage user source nvm in .bash_profile?

@ljharb
Copy link
Member

ljharb commented Apr 14, 2020

It should be sourced every time each shell starts.

@mikeymandm
Copy link

mikeymandm commented Apr 14, 2020

@benwinding
Copy link

benwinding commented Oct 13, 2020

I was able to speed up terminal starts by changing the load script to have the --no-use option:

# Load NVM
export NVM_DIR="$HOME/.nvm"
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" --no-use

It's like 1 second faster for every terminal start now... which is life changing!

@ljharb
Copy link
Member

ljharb commented Oct 14, 2020

For those that have found the standard process (without --no-use) slow, please check out #2317, and if it's faster, please comment with your benchmarks.

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

No branches or pull requests

5 participants