-
-
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
NVM getting very slow on startup in Bash #1277
Comments
What's |
You can also try adding |
@ljharb
|
Do you have a |
@ljharb the one line I have in that file is Tried to remove it, didn't make any difference, so added it back. |
@ahennie in a file called nVmrc, you have that line? Can you provide a little more info on your Mac? Do you have an SSD, how old is it, how fast/much RAM, etc? |
This is also very slow for me on gentoo linux. |
@mitermayer can you also go through the same steps above and see if you get the same or different results? |
@ljharb Sorry, that was .nPmrc. I don't have a .nVmrc-file. It must be sw, not hw related. I got Macbook Pro 15" i7, 16gb RAM, SSD. What could it be? |
@ahennie that should be fast enough. Basically it's that |
@ljharb thanks. it wasnt slow like this earlier. does the number of global modules affect the speed? other things I can do to speed it up? |
When you say "earlier" do you mean on an earlier version, before I was doing prefix checking? Or do you mean on the same version of nvm? |
same issue too. |
@ljharb it's hard to say. I installed nvm months ago, but never really used node. However loading the bash has always been fast. I have been coding node a lot more lately, including installing a few global modules, and it suddenly have gotten slower. I also updated to the newest version of nvm, npm and node. Deleted a few global modules now, but it's still slow. So I think the slowness was intruduced in any of the updates. |
It's likely the |
@ljharb suddenly it's faster again. don't know why. but I thought you should know, before you spend to much time on it. |
I just checked out the latest tag and noticed this. I forget what tag I was previously using but it was in the v0.31 series. Adding the the |
Experiencing the same problem. Everything was fine until I upgraded OSX to Sierra a few days ago. Ran brew update and brew upgrade, but it's still slow. When I run
I'm running a 2013 15in macbook pro. 2.7Ghz, 16GB RAM. |
@Nick011 |
same issue here... |
@nico1510 right, the |
To investigate the performance issues myself, I tried to setup some performance logging in a forked branch: and I also come to the conclusion that the biggest issue is starting node. ( |
@martinheidegger i think you're spot on. If anyone can come up with a way to perfectly emulate |
@ljharb I ran another test for the performance of I |
I opened nodejs/help#396 in order to figure out if Node.js and NPM could share the same logic in order for nvm to not need to rely on Node and/or make NPM faster. Quoting:
I guess same can be said of nvm? |
$NVM_DIR/nvm.sh is a slow script and has doubled time to load zsh. In this commit, the script is not loaded until required. cf. nvm-sh/nvm#1277
$NVM_DIR/nvm.sh is a slow script and has doubled time to load zsh. In this commit, the script is not loaded until required. cf. nvm-sh/nvm#1277
this code snippet has really used my startup time while ensuring that I also have access to global packages as well as yarn globals and yarn project have same node env version. 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
NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
NODE_GLOBALS+=(node nvm yarn)
_load_nvm() {
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
}
for cmd in "${NODE_GLOBALS[@]}"; do
eval "function ${cmd}(){ unset -f ${NODE_GLOBALS[*]}; _load_nvm; unset -f _load_nvm; ${cmd} \$@; }"
done
unset cmd NODE_GLOBALS
export PATH="$PATH:$HOME/.yarn/bin"``` |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For future reference, nvm supports mostly POSIX shells - ksh, dash, sh, bash, zsh in particular. |
@milahu This was implemented long time ago already, together with other improvements. However it never got merged due to reasons you can read yourself, thought it might be worth mentioning. There is a hard fork which is fast and also does this caching. Here is the reasoning and the hard fork, I am using that one for very long time and didn't had any problems with it wzrdtales/nvm-ng#2 Don't forget the --fast-reuse flag to activate this fast path. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@tilsmen Careful using any forks; that one's missing over 2 years of improvements. |
yes i know @ljharb but nothing really meaningful was added (for my terms, not in general don't get me wrong not trying to offend here) during this 2 years. The difference of the hard fork and your original are just two commits in the hard fork which are like a show stopper to me from your work. Everything is working with this fork also with the newest node version without any flaw and I have the benefit of not being disturbed in my workflow and still able to use my console normal. So I think it is reasonable, if you by any chance improve here the loading times let me know though. |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
Well, you can create a few aliases for the tools that you use, the advantage is that when I open my shell for random things outside Node ecosystem it's fast, and when I use node/npm/whatever I can pay the penalty. To lazy load multiple aliases:
|
This alias method has been discussed extensively on this gist; I myself am using this version (with bash)
With this solution, prior to launching node or any other node-based binaries, your shell has following wrappers:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
If you are looking for a lazy load for zsh: |
I love NVM, but I've noticed that NVM is getting really slow during startup. See attached screenshot for what I mean: http://take.ms/LPOv3
Is this a bug or is something wrong on my Mac?
The text was updated successfully, but these errors were encountered: