Repository navigation
nvm_resolve_local_alias default has bad performance #3416
Copy link
Copy link
Open
Labels
performanceThis relates to anything regarding the speed of using nvm.This relates to anything regarding the speed of using nvm.pull request wantedThis is a great way to contribute! Help us out :-DThis is a great way to contribute! Help us out :-D
Description
Operating system and version:
macOS 14.5
nvm debug output:
Details
nvm --version: v0.39.7
$TERM_PROGRAM: iTerm.app
$SHELL: /opt/homebrew/bin/bash
$SHLVL: 1
whoami: 'my'
${HOME}: /Users/my
${NVM_DIR}: '${HOME}/.nvm'
${PATH}: ${HOME}/.pyenv/shims:${HOME}/.pyenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:${HOME}/.local/bin:${HOME}/.gobrew/current/bin:${HOME}/.gobrew/bin:${HOME}/anaconda3/bin:${HOME}/go/bin:${HOME}/.deno/bin:${HOME}/bin/flutter/bin:${HOME}/bin:${HOME}/Library/Python/2.7/bin:${HOME}/.cargo/bin:${HOME}/go/bin:${HOME}/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/opt/homebrew/opt/openjdk@17/bin:${HOME}/.sdkman/candidates/gradle/current/bin:${HOME}/.pyenv/bin:${HOME}/.cargo/bin:${HOME}/go/bin:${HOME}/.gobrew/current/bin:${HOME}/.gobrew/bin:${NVM_DIR}/versions/node/v22.5.1/bin:${HOME}/.local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/puppetlabs/bin:/Applications/iTerm.app/Contents/Resources/utilities:${HOME}/.rvm/bin:/usr/local/bin
$PREFIX: ''
${NPM_CONFIG_PREFIX}: ''
$NVM_NODEJS_ORG_MIRROR: 'http://npm.taobao.org/mirrors/node'
$NVM_IOJS_ORG_MIRROR: ''
shell version: 'GNU bash, version 5.2.32(1)-release (aarch64-apple-darwin23.4.0)'
uname -a: 'Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:13:18 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6030 arm64'
checksum binary: 'sha256sum'
OS version: macOS 14.5 23F79
awk: /usr/bin/awk, awk version 20200816
curl: /usr/bin/curl, curl 8.6.0 (x86_64-apple-darwin23.0) libcurl/8.6.0 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.12 nghttp2/1.61.0
-bash: wget: command not found
wget: (wget -c),
sed: /usr/bin/sed
cut: /usr/bin/cut
basename: /usr/bin/basename
rm: /bin/rm
mkdir: /bin/mkdir (_omb_util_alias_init_mkdir)
xargs: /usr/bin/xargs
git: /usr/bin/git, git version 2.39.3 (Apple Git-146)
grep: /usr/bin/grep (grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}), grep (BSD grep, GNU compatible) 2.6.0-FreeBSD
nvm current: v22.5.1
which node: ${NVM_DIR}/versions/node/v22.5.1/bin/node
which iojs:
which npm: ${NVM_DIR}/versions/node/v22.5.1/bin/npm
npm config get prefix: ${NVM_DIR}/versions/node/v22.5.1
npm root -g: ${NVM_DIR}/versions/node/v22.5.1/lib/node_modulesnvm ls output:
Details
v18.20.4
-> v22.5.1
default -> node (-> v22.5.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v22.5.1) (default)
stable -> 22.5 (-> v22.5.1) (default)
lts/* -> lts/iron (-> N/A)
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.4
lts/iron -> v20.15.1 (-> N/A)How did you install nvm?
install script in readme
What steps did you perform?
- use this script in thread: https://stackoverflow.com/a/5015179/4691964
- use
gdate(fromcoreutils) instead ofdateto make%Nwork - analyze the log
What happened?
Found the nvm_resolve_local_alias default have bad performance.
It took 2 seconds in my M3 chip macbookPro:

Why it need 2 seconds to get default version? seems it's just a simple task.
What did you expect to happen?
nvm_resolve_local_alias default should be quick, and save 2 seconds for my bash startup.
Is there anything in any of your profile files that modifies the PATH?
~/.bashrc
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
performanceThis relates to anything regarding the speed of using nvm.This relates to anything regarding the speed of using nvm.pull request wantedThis is a great way to contribute! Help us out :-DThis is a great way to contribute! Help us out :-D
Activity
[-]nvm_resolve_local_alias default performance[/-][+]`nvm_resolve_local_alias default` have bad performance[/+][-]`nvm_resolve_local_alias default` have bad performance[/-][+]`nvm_resolve_local_alias default` has bad performance[/+]hridhinvarkeyjoseph commentedon Oct 3, 2026
I ran into this while looking into #3930. On v0.40.3 (macOS 27, arm64, zsh),
nvm_resolve_local_alias defaulttook about 104ms per call (avg of 10, underenv -i).Looking at this function, there seem to be two costs:
nvm_resolve_aliasfollowing a chain like this one in the report (default -> node -> stable -> 22.5). The implicit aliases (node,stable) have to get the installed versions, which is probably where most of the time goes.nvm_versionalways runs on the result, even when the chain already ended at an exact installedvX.Y.Z.The second one is small and similar to the fast path in #3937. The first looks like the bigger win for this report. Before writing anything, which would you rather I look at, and would the second be better folded into #3937 than as a separate PR?
[Perf] `nvm_resolve_local_alias`: skip `nvm_version` for an exact, in…
[Perf] `nvm_version`, `nvm_is_version_installed`: avoid forks
[Perf] mark the startup profiling baseline
[Perf] `nvm_die_on_prefix`: detect the OS only when it is needed
[Perf] `nvm_npmrc_bad_news_bears`: scan npmrc files without forking `…
[Perf] `nvm_get_os`: read `/etc/os-release` instead of forking `uname…
[Perf] `nvm_echo`: use the `printf` shell builtin under zsh
[Perf] `nvm_is_valid_version`, `nvm_validate_implicit_alias`: avoid f…
[Perf] `nvm_version_greater`, `nvm_version_greater_than_or_equal_to`:…
[Perf] `nvm_die_on_prefix`: detect the OS only when it is needed
6 remaining items
[Perf] `nvm_die_on_prefix`: detect the OS only when it is needed
[Perf] `nvm_npmrc_bad_news_bears`: scan npmrc files without forking `…
[Perf] `nvm_get_os`: read `/etc/os-release` instead of forking `uname…
[Perf] `nvm_echo`: use the `printf` shell builtin under zsh
[Perf] `nvm_is_valid_version`, `nvm_validate_implicit_alias`: avoid f…
[Perf] `nvm_version_greater`, `nvm_version_greater_than_or_equal_to`:…
[Perf] `nvm_resolve_local_alias`: skip `nvm_version` for an exact, in…
[Perf] `nvm_resolve_local_alias`: skip `nvm_version` for an exact, in…
[Perf] `nvm_version`, `nvm_is_version_installed`: avoid forks
[Perf] `nvm_die_on_prefix`: detect the OS only when it is needed
[Perf] `nvm_npmrc_bad_news_bears`: scan npmrc files without forking `…
[Perf] `nvm_get_os`: read `/etc/os-release` instead of forking `uname…
[Perf] `nvm_echo`: use the `printf` shell builtin under zsh
[Perf] `nvm_is_valid_version`, `nvm_validate_implicit_alias`: avoid f…
[Perf] `nvm_version_greater`, `nvm_version_greater_than_or_equal_to`:…