WSL: startup bash too slow with nvm loading in .bashrc config
Describe
It is too slow to startup a new bash shell, 10sec or so, with following 2 lines at the bottom of .bashrc:
export NVM_DIR=“/home/mzvast/.nvm” [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm
In TMUX, it is extremely terrible to split a window and wait for a new bash to init.
It seems that every new bash needs to be inited with same amount of time,no matter whether there has bash instances been running in background.
Reproduce steps
- run
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash - reopen bash, it gets slow on init immediately
OS version,etc.
system:14393 win10 pro x64 hardware: Intel i5 2.5GHz, 6GB RAM, 256GB SSD
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 29
- Comments: 49 (3 by maintainers)
This is still an issue.
Problem solved fix don’t use nvm =) Thanks
We tracked down the slow nvm start-up time using xperf, and it’s a known perf bottle neck in clone\fork when copying address space information. We were already planning on the fix so it should be out to insider builds soon.
I’m using 16241 and it’s still unacceptably slow. 😕
Confirming. It’s adding ~30s to shell startup on my machine. (Core i7 6500k w/ M.2 SSD)
Edit: Workaround. Use
ninstead. https://github.com/tj/nA fix for this should be out for insider builds soon that reduces nvm start-up by ~60%. On my test vm it took the launch from 12 seconds to 5 seconds. @benhillis reminded me that percentages are hard, and it sounds much better if we say it’s ~2.5x!!! faster 😃.
We understand where the remaining time is being spent and are tracking additional work to bring this down closer to native Linux speeds.
FYI: https://gist.github.com/lukeshiru/e239528fbcc4bba9ae2ef406f197df0c maybe that helps
I’m also experiencing this. Quick fix for people who don’t use nvm too often - in your bashrc put the nvm related lines into a function and call the function when you need to use nvm. This way it doesn’t slow bash down while starting, you only need to wait right before you use it for the first time.
Gist: https://gist.github.com/KenG98/2d084a9859637cdd1614ba27485e2ef9
I spent some time trying to work around this problem on an RPi today and thought I ought to share some data in case it is helpful: strace_nvm_on_rpi4.zip
time ionice -c 1 -n 0 nice -n -20 sh $NVM_DIR/nvm.sh# outputs ~0.8s instead of ~1.2s$HOME/.nvmto/tmp/.nvm_homeat start-up and setting$NVM_HOMEto match) didn’t seem to improve anythingstrace -T -ttt -o strace.out sh $NVM_DIR/nvm.shperl strace_analyzer_ng_0.09-jrq.pl strace.out > analyzer_output.txt`head -n 300 strace.out |tail -n 40` # to see context around line 288
Also, though you probably all figured this out already:
The
-ffoption causes a separate trace file to be written for each PID, so yes (man strace.1).TL;DR Here’s what I ultimately came up with: set path, etc. to a default node version then lazy load
nvmwith an alias as others have done (only tested on bash but seems to do just what I wanted):So now, just after logging in, we can do this (assuming
nvm install 10was run previously):I’ve wrapped
nvmsetup in a function, so it’s lazy-loaded but seamless to use. Give it a shot!https://github.com/ravron/dotfiles/blob/2093bb4b257db221f31fa900cfc8cd394476a7cd/.bashrc#L233-L243
Related Thread: https://github.com/creationix/nvm/issues/782
If you installed node without nvm (the system installation), and that is what you usually use, and you use nvm for only switching to other versions of node, then this comment on that thread is a nice workaround
Great to hear. I’m going to close this out as fixed for insiders and we can take a look if anything new comes up.
Thanks for the snippet @well1791 it didn’t speed stuff up much but it did stop stuff from constantly telling me that nvm wasn’t installed when it was.
@mrmckeb thanks for the feedback. Pushing out changes to the Creator’s update is currently gated through servicing criteria which has a pretty high bar and requires data on the impact. We would like to get to the point were mid-cycle updates can go out, but unfortunately aren’t there yet. This change will likely fall into the other category where it is flighted to insider builds and available in the next official release of Windows.
after commenting the command below in .bashrc, i have removed a 4 second+ delay to the loading of the terminal, any idea how to make this faster at least?thanks, using ubuntu 16 :
export NVM_DIR=“/home/username/.nvm” [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm
probably you should exam your .bashrc For initializing fasd would cause slow startup