-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Loading nvm is unbelievably slow (7-46 seconds) #1261
Comments
Try changing the line in your profile that sources |
Yep, |
Is there a local workaround solution to this issue? Or is it just something that |
I'm not aware of a workaround, since I'm still not sure why it's particularly slow. |
What's interesting is that this only happens the first time I load nvm after boot. All future loads in other terminal tabs are pretty fast, about ~1 second. What's different the first time it loads? |
Hmm, that's a good question. I wonder if your filesystem is caching things (like what's inside $NVM_DIR, or something)? |
Any ideas on how I could check whether it's doing that? Also, is there a good way for me to profile each step in the loading process? I could put a |
I was thinking it cached the directory listing (not the contents), but I have no idea. I know that |
Right, that definitely makes more sense. :P I'm busy the next couple of days, but after that, I'll try to profile stuff and let you know how that goes. |
Last boot, loading nvm took about 8 seconds. I ran I haven't analyzed the output much yet (will try again in a couple of days), but just the zprof output might be useful. |
@polybuildr thanks! As expected, |
As far as I can tell from the zprof output, it looks like it only gets called once every time (from the "calls" column). I tried to see - crudely - how many seconds the
Mostly 1 or 2 seconds, but sometimes ~9 seconds. Any idea why this drastic variation? Also, are there any other possible culprits than |
I'm not sure why there's variation - it's all internal to Other than that, there's calls into |
Last boot, the load time was 70 seconds 😞 I did another So whatever it is, it definitely happens inside
So, while there are some other issues, this is definitely the whopper. As a workaround, I've simply hardcoded my current version's npm prefix where Additionally, I think I should also file a bug in |
@polybuildr filing an issue in |
I've filed the issue at npm/npm#14458. |
Oh and thanks a lot for confirming that this hardcoding solution will work for now! :) |
I'm also experiencing incredible slow load time for NVM.
Timing . "$NVM_DIR/nvm.sh" I'm trying to understand the work-around - where exactly do I write the node version? |
I added a bunch of debug info to find the slow parts of If I want to know what the npm version is, I can just run I don't understand exactly what @ljharb what do you think about skipping these two calls to The next slowest portion of init is |
@nylen you're quite right that the And no, I will not allow any way to skip the prefix checks; it's necessary on every single call to |
Ok, can you explain a bit about what the prefix checks are actually doing? |
Sure. The prefix is what determines Many people have it set from following ill-advised tutorials, for example. By adding these checks, a very very large number of monthly bug reports stopped coming in. Basically, it's doing |
On this small machine I'm using, I would still like a way to skip as many of those three phases as possible ( |
|
|
|
The approach in #1737 works well for me. |
nylen/dotfiles@33bb4a8 / nylen/dotfiles@cdb8508 also works for me and doesn't require any modifications to nvm code. Before these changes, initializing For me, personally, the performance improvement is dramatic and well worth the trade-offs. |
I made a dynamic NVM loader to speed things up. This way we don't run the NVM loader code every time we open a new terminal window.
and then in .zshrc (or .bashrc)
You could even put this script in your .nvm directory if you don't want it cluttering your $HOME. EDIT: I added aliases for npm and node as well |
Don't forget |
So I am now using this code snippet and it has really used my startup time in zsh shell while ensuring that I also have access to global packages as well as yarn globals and yarn project have same node env version. Would like to know if it works for others as well. 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"``` |
I've been using nvm for quite some time now and I recently installed it on a new laptop running Ubuntu 16.04. I've been experiencing extremely high load times: between 7 and 46 seconds on both
zsh
(my primary shell) as well asbash
.Here's the output of
nvm debug
(I hadchsh
-ed to trybash
):I tried
rm -rf ~/.nvm
and reinstalled, but there was no improvement. I downgraded to 0.31.7 and saw some improvement - most load times were around 7 seconds now.Please let me know whether there are some additional debugging steps that might help - I really can't believe that loading nvm could be this slow without something messing around!
The text was updated successfully, but these errors were encountered: