-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sourcing nvm.sh is slow even with --no-use
#1978
Comments
By default, this is because it runs As for your approach, that has a number of caveats - including that In other words, it would not be a good idea to add it to the documentation, because it's error-prone and comes with caveats. |
@ljharb I do not understand the relevance of the caveats you listed. I am not suggesting my solution to replace full initialization of
as currently recommended, With the script I suggested, |
That's a very fair point - but I'm still not sure why with I don't think the solution is to make (Note that |
--no-use
@ljharb Thanks for re-opening this. It appears $ (nvm_supports_source_options && echo true) || echo false
true
$ (nvm_supports_source_options && echo true) || echo false
false
$ i=0; while nvm_supports_source_options; do echo -n .; ((i++)); done; printf "\n%s\n" $i
..
2
$ i=0; while nvm_supports_source_options; do echo -n .; ((i++)); done; printf "\n%s\n" $i
0
$ i=0; while nvm_supports_source_options; do echo -n .; ((i++)); done; printf "\n%s\n" $i
.......
7 The current implementation of FWIW, I updated my function _install_nvm() {
unset -f nvm npm node
# Set up "nvm" could use "--no-use" to defer setup, but we are here to use it
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This sets up nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # nvm bash_completion
"$@"
}
function nvm() {
_install_nvm nvm "$@"
}
function npm() {
_install_nvm npm "$@"
}
function node() {
_install_nvm node "$@"
} That suits me better, because there is no loading of anything until I need it, but when I need |
Interesting, thanks - that's helpful. I'll see about fixing |
Looks like this is a bug in Gnu bash 3.2.x, which is what Apple ships, apparently because of licensing issues. ( nvm_supports_source_options() {
[ "_$( . /dev/stdin yes 2> /dev/null <<'EOF'
[ $# -gt 0 ] && echo $1
EOF
)" = "_yes" ]
} |
That seems totally workable! I’ll test it out and report back. |
With this solution:
I still losing |
Spent a hour of debugging my .zshrc file, thanks god I found why |
@milushov what did you find out? |
I use this for zsh: if [ -s "$HOME/.nvm/nvm.sh" ]; then
export NVM_DIR="$HOME/.nvm"
nvm_cmds=(nvm node npm yarn)
for cmd in $nvm_cmds ; do
alias $cmd="unalias $nvm_cmds && unset nvm_cmds && . $NVM_DIR/nvm.sh && $cmd"
done
fi |
I am using Even when i use
As we can see
As a result Should I go ahead with #1978 (comment) |
@AnandNidamanuru what version of nvm? v0.37.0 introduced a major performance improvement. Can you try on the latest version? |
My nvm version is 0.37.2 :( I believe the issue is with source to /dev/stdin. But I am no expert in shell |
@AnandNidamanuru would you mind filing a new issue, and filling out the issue template in its entirety? |
Thanks @ljharb for your quick replies. I will do that |
@ljharb love your work, but how is using Would this be possible? |
No, because then that would be incorrect, since the prefix can change based on the current directory as well as the value of env vars. However, that particular slowness has been resolved since this was closed. If you’re still having performance problems in the latest version, please file a new issue. |
@ljharb Yes, the slowness has been resolved when using |
@martin-braun i meant that the slowness of If you're still finding it necessary to use |
I start up a lot of terminal windows on my Mac and for some reason the commands
that I had in my
.bashrc
would sometimes take a noticeable and annoying amount of time to run. (Maybe as long as 2 seconds.) My solution was to setup environment variables likeNVM_DIR
as usual but to fully defer all othernvm
setup until first use by adding these definitions to my.bash_profile
script:I am not familiar enough with other shells to say how portable that is (I am using GNU
bash
), but I suggest you at least add it to the documentation (if not the install script) so that people can have an easy way to install deferred setup ofnvm
that is truly deferred.The text was updated successfully, but these errors were encountered: