Repository: nvm-sh/nvm

Issue #539: nvm.sh is slow (200ms+)
Created: 2014-09-30T21:48:20Z
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.

Duplicate issue #1774: nvm.sh and bash_completion add 2 seconds to shell load time
Created: 2018-04-04T18:21:46Z
Operating system and version:
macOS Sierra 10.12.6


nvm debug output:
I don't think it is relevant for this issue but here it is.




nvm --version: v0.33.8
$TERM_PROGRAM: iTerm.app
$SHELL: /bin/zsh
$HOME: /Users/abergonzo
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.2 (x86_64-apple-darwin16.0)'
uname -a: 'Darwin 16.7.0 Darwin Kernel Version 16.7.0: Tue Jan 30 11:27:06 PST 2018; root:xnu-3789.73.11~1/RELEASE_X86_64 x86_64'
OS version: Mac 10.12.6 16G1314
curl: /usr/bin/curl, curl 7.54.0 (x86_64-apple-darwin16.0) libcurl/7.54.0 SecureTransport zlib/1.2.8
wget: /usr/local/bin/wget, GNU Wget 1.19.4 built on darwin16.7.0.
git: /usr/bin/git, git version 2.14.3 (Apple Git-98)
grep: grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}), grep (BSD grep) 2.5.1-FreeBSD
awk: /usr/bin/awk, awk version 20070501
sed: illegal option -- -
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: /usr/bin/sed,
cut: illegal option -- -
usage: cut -b list [-n] [file ...]
       cut -c list [file ...]
       cut -f list [-s] [-d delim] [file ...]
cut: /usr/bin/cut,
basename: illegal option -- -
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]
basename: /usr/bin/basename,
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
       unlink file
rm: /bin/rm,
mkdir: illegal option -- -
usage: mkdir [-pv] [-m mode] directory ...
mkdir: /bin/mkdir,
xargs: illegal option -- -
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
xargs: /usr/bin/xargs,
nvm current: v9.10.0
which node: $NVM_DIR/versions/node/v9.10.0/bin/node
which iojs: iojs not found
which npm: $NVM_DIR/versions/node/v9.10.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v9.10.0
npm root -g: $NVM_DIR/versions/node/v9.10.0/lib/node_modules


nvm ls output:
I don't think it is relevant for this issue but here it is.



        v8.11.0
->      v9.10.0
         system
default -> node (-> v9.10.0)
node -> stable (-> v9.10.0) (default)
stable -> 9.10 (-> v9.10.0) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> v8.11.0)
lts/argon -> v4.9.0 (-> N/A)
lts/boron -> v6.14.0 (-> N/A)
lts/carbon -> v8.11.0



How did you install nvm? (e.g. install script in readme, Homebrew):
Install script in README. (I thought brew installation was not supported as stated in the docs)


What steps did you perform?
I added the following to my .bashrc file.


[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" 
(I know bash_completion will probably work only with bash and I know I can install nvm as a zsh plugin but I change shell sometimes)

What happened?
With those 2 lines enabled:

[abergonzo:~]$ /usr/bin/time zsh -i -c exit
        2.45 real         1.08 user         0.97 sys
Without those 2 lines:
[abergonzo:~]$ /usr/bin/time zsh -i -c exit
        0.43 real         0.20 user         0.14 sys
So the startup of a shell (zsh in my case) was slowed down by ~2 seconds adding those 2 lines.

What did you expect to happen?
I expected the loading to be faster or at least that the time it adds to be in the docs as it is significant.
(Thanks for your work!)

Closing comment (2018-04-04T18:25:16Z): Duplicate of #539 and #1242.
Workaround here
Probably worth to add to the docs as I am not the first one? :)