Skip to content

nvm_resolve_local_alias default has bad performance #3416

Open
@futurist

Description

@futurist

Operating system and version:

macOS 14.5

nvm debug output:

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_modules

nvm ls output:

       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?

  1. use this script in thread: https://stackoverflow.com/a/5015179/4691964
  2. use gdate(from coreutils) instead of date to make %N work
  3. analyze the log

What happened?

Found the nvm_resolve_local_alias default have bad performance.

It took 2 seconds in my M3 chip macbookPro:
image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceThis relates to anything regarding the speed of using nvm.pull request wantedThis is a great way to contribute! Help us out :-D

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions