nvm: nvm.sh is slow (200ms+)
On my system (OSX 10.9.5 & bash 4.3.27), nvm adds a lot of time to my .bash_profile:
$ time source ~/.nvm/nvm.sh
real 0m0.218s
user 0m0.107s
sys 0m0.163s
–This is much slower than rvm–:
$ time source ~/.rvm/scripts/rvm
real 0m0.011s
user 0m0.005s
sys 0m0.006s
I do not use .nvmrc files.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 5
- Comments: 51 (21 by maintainers)
Commits related to this issue
- [Performance] make auto-using faster. Per https://github.com/creationix/nvm/issues/539#issuecomment-236830764 — committed to nvm-sh/nvm by ljharb 8 years ago
- .bashrc: lazy-load nvm using node/npm aliases See https://github.com/creationix/nvm/issues/539#issuecomment-245791291 — committed to josephfrazier/dotfiles by josephfrazier 7 years ago
- Remove some bloat and modify nvm sourcing * nvm sourcing with brew installed version is slow and bottlenecks shell creation performance * see https://github.com/creationix/nvm/issues/539 — committed to narsaynorath/dotfiles by narsaynorath 5 years ago
- use `mafredri/zsh-async` to accelerate use `mafredri/zsh-async` to accelerate the nvm plugin, now works faster https://github.com/nvm-sh/nvm/issues/539#issuecomment-403661578 — committed to pre1ude/oh-my-zsh by pre1ude 5 years ago
- Load nvm async Nvm was the slowest part of my prompt. Opening a new shell is super quick now. Reference: https://github.com/nvm-sh/nvm/issues/539#issuecomment-403661578 — committed to MarcelRobitaille/dotfiles by MarcelRobitaille 4 years ago
For anyone who comes across this in the future;
nvm
kills my productivity because bash takes two orders of magnitude longer to create a new shell when a default alias exists. As a workaround, I added this hack to my.bash_profile
afternvm.sh
is loaded:Delete the default alias andShell creation is fast again, and I still have a default node through the alias hack. First run of.nvmrc
;node
ornpm
has the startup penalty, but that’s a far better compromise than typingnvm use v4.4.7
every time I want to start a REPL.Maybe need use zsh-async? Works very fast
In zsh I use lazy loading for source files. This is not a solution but shell runs faster.
the
--no-use
solves the problem indeed, thanksWhen I have either a default alias, or an
.nvmrc
file, or both, it’s slow. When I have neither, it’s fast.I think the best solution is to add
--no-use
to your profile file - ie,. "$NVM_DIR/nvm.sh" --no-use
. Does that solve the problem for whoever’s subscribed to this issue?That wouldn’t work for all the other non-zsh shells that nvm supports.
For people who want to respect the
.nvmrc
without thinking, and still preserve the lazy loading so that shell boot and cd are still fast in zsh, I managed to put together a nice alias method off of @parasyte’s method.The nice thing is that this allows the system node and yarn to still work (as other home-brew dependencies often install them). It works by resetting the alias on
cd
so that the next time you run, it will check to make sure your version is correct (rather than running on cd, which is slow and too optimistic).@belozer solution is by far the fastest one on my machine
How about this?
What could be missing with this code?
Gotcha. That is a nice little enhancement. I misunderstood that you were providing a tip. 😃
I guess I’ll have to keep the alias, and stay hopeful that one day the startup time will get better! Cheers.
@belozer - that is what I needed, after a lot of searching. I was using a zsh nvm plugin (tried a couple of different ones), but your solution is the fastest on OSX & Linux.
For that and other reasons, I gave up and switched to managing node with brew. It’s ugly, but a few aliases will take care of that, surely.
@medisoft If you want to be closer to nvm’s internal code, you could use:
That still fails to set the MANPATH but that’s pretty close.
@ljharb