Repository: nvm
Issue: zsh initialization performance
Labels: shell: zsh,pull request wanted,performance

<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->

#### Operating system and version:

#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->

```sh
nvm --version: v0.40.0
$SHELL: /usr/bin/zsh
$SHLVL: 1
whoami: 'devlin'
${HOME}: /home/devlin
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: /opt/oracle/instantclient_21_5:${HOME}/Developments/flutter/bin:${HOME}/Developments/flutter/bin:/usr/local/bin:${NVM_DIR}:${NVM_DIR}/versions/node/v20.12.2/bin:${HOME}/development/flutter/bin:${HOME}/.cargo/bin:${HOME}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/sbin:/usr/local/bin:/snap/bin:/snap/bin:${HOME}/.local/share/JetBrains/Toolbox/scripts
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: ''
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'zsh 5.8.1 (x86_64-ubuntu-linux-gnu)'
uname -a: 'Linux 6.5.0-45-generic #45~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 15 16:40:02 UTC 2 x86_64 x86_64 x86_64 GNU/Linux'
checksum binary: 'sha256sum'
OS version: Ubuntu 22.04.4 LTS  
random-funcs:       srandom/random
regex-funcs:        internal
compiled limits:
sprintf buffer      8192
maximum-integer     2147483647
awk: /usr/bin/awk, mawk 1.3.4 20200120
curl: /usr/bin/curl, curl 7.81.0 (x86_64-pc-linux-gnu) libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.18
wget: /usr/bin/wget, GNU Wget 1.21.2 built on linux-gnu.
git: /usr/bin/git, git version 2.34.1
ls: cannot access 'grep:': No such file or directory
grep: grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox} (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}), grep (GNU grep) 3.7
sed: /usr/bin/sed, sed (GNU sed) 4.8
cut: /usr/bin/cut, cut (GNU coreutils) 8.32
basename: /usr/bin/basename, basename (GNU coreutils) 8.32
rm: /usr/bin/rm, rm (GNU coreutils) 8.32
mkdir: /usr/bin/mkdir, mkdir (GNU coreutils) 8.32
xargs: /usr/bin/xargs, xargs (GNU findutils) 4.8.0
nvm current: v20.12.2
which node: ${NVM_DIR}/versions/node/v20.12.2/bin/node
which iojs: iojs not found
which npm: ${NVM_DIR}/versions/node/v20.12.2/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v20.12.2
npm root -g: ${NVM_DIR}/versions/node/v20.12.2/lib/node_modules

```
</details>

#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->

```sh
->     v20.12.2
default -> node (-> v20.12.2)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v20.12.2) (default)
stable -> 20.12 (-> v20.12.2) (default)
lts/* -> lts/iron (-> v20.12.2)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.20.2 (-> N/A)
lts/iron -> v20.12.2
```
</details>

#### How did you install `nvm`?
install script in readme

#### What steps did you perform?

Opening a Terminal (Ubuntu)

#### What happened?

The terminal take long time since a few days to "initialise", I am using zsh and oh-my-zsh
In addition the nvm command are also slow


I have zprofed

num  calls                time                       self            name
-----------------------------------------------------------------------------------
 1)    1       20891.60 20891.60   97.38%  11980.82 11980.82   55.85%  nvm_auto
 2)    2        8901.02  4450.51   41.49%   6244.29  3122.14   29.11%  nvm
 3)    1        1582.49  1582.49    7.38%   1576.41  1576.41    7.35%  nvm_ensure_version_installed
 4)    2        1019.62   509.81    4.75%   1019.62   509.81    4.75%  nvm_grep


#### What did you expect to happen?
Quicker access to my cmd line as now it take a few seconds to load it

#### Is there anything in any of your profile files that modifies the `PATH`?
# zmodload zsh/zprof

if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
zstyle ':omz:update' mode auto      # update automatically without asking
zstyle ':omz:plugins:nvm' lazy yes
plugins=(git python docker docker-compose zsh-autosuggestions)
source $ZSH/oh-my-zsh.sh
alias dcd="docker compose down"
alias dcu="docker compose up -d"
alias dcl="() {docker logs -f $1}"
alias dcr="dcd ; dcu"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
export PATH="$NVM_DIR:$PATH"
export PATH="/usr/local/bin:$PATH"
export ANDROID_HOME=/home/devlin/Android/Sdk
export ANDROID_NDK=/home/devlin/Android/Sdk/ndk
export PATH="$HOME/Developments/flutter/bin:$PATH"
export PATH="/home/devlin/Developments/flutter/bin:$PATH"
export PATH="/opt/oracle/instantclient_21_5:$PATH"
export LD_LIBRARY_PATH="/opt/oracle/instantclient_21_5:$LD_LIBRARY_PATH"
# Load Angular CLI autocompletion.
source <(ng completion script)
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# zprof