-
Notifications
You must be signed in to change notification settings - Fork 847
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
startup bash too slow with nvm loading in .bashrc config #776
Comments
probably you should exam your .bashrc |
No lag on my Core I7 & SSD Samsung 850 pro, startup time is near 0 sec. Strange thing, some second to wait using the "sudo" command. |
@adouzzy You are right, after commenting out following lines,which loads nvm ,it starts fine again. #export NVM_DIR="/home/mzvast/.nvm" I think this may be a performance issue with bash on windows, because the same bash config startup very fast in my vps. |
I've also noticed nvm slowing down bash launch. It would be very helpful if we could narrow down what is causing the delay via an strace. |
This can be partially solved by using |
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" |
Confirming. It's adding ~30s to shell startup on my machine. (Core i7 6500k w/ M.2 SSD)
Edit: Workaround. Use
|
Confirming that this is still an issue in the latest Selfhost. |
Thanks for the report @reybango. If someone can collect an strace with relative timestamp and share them out, then it will be easy to see where the delay is coming from.
And, share out the trace files. |
Here are my trace files: |
I get "strace: exec: Exec format error" when running that :/ |
I would like to say that I (like @bmayen ) get |
@sunilmut could you give more precise instructions on running the strace? |
I believe the right command is |
Being a bash script, nvm is executing various command in various processes. Strace is logging each of these processes in a separate file. Since I'm not sure which is the best way to sort them without losing info, I just tarball'd them :| |
@arcanis - Thanks for sharing the traces. The idea is to see which command is taking long to execute. Since the trace file has the timestamps, it would hopefully make it easier to gather that information. I haven't gone through the traces yet, but it's available here for anyone to parse and see. |
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. |
@stehufntdev Will releases coincide with Windows releases? Or is there a chance of a mid-cycle update? As this is still technically a pre-release, it would be cool to see features added to the WSL more regularly - installing the Insider builds of Windows can obviously have other effects... |
@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. |
A 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. |
@stehufntdev note that I had seen better perf in 16179 than in 16184. Went from maybe 5-10 seconds max to nearly 2 minutes now. I commented the loading of nvm in .zshrc with no improvement. Then I commented loading the zsh shell (oh my zsh) altogether and the normal bash shell loads near instantaneous. Now the one behavior I'm seeing while loading the zsh shell is that during the long length of time, if I break out using CTRL-C, the zsh shell is loaded. Maybe this is some type of hang or race condition? |
@reybango, thanks for the update. Can you start a new thread on the zsh issue so we can take a look? |
I'm using 16241 and it's still unacceptably slow. 😕 |
The nvm path slowed down my bash (and zsh) on my Ubuntu 16.04, too. After removing it from .bashrc (or .zshrc) it's much better. |
Problem solved fix don't use nvm =) |
This is still an issue. |
Related Thread: nvm-sh/nvm#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 |
FYI: https://gist.github.com/lukeshiru/e239528fbcc4bba9ae2ef406f197df0c maybe that helps |
Still having this problem. Wicked slow. |
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. |
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've wrapped |
I switched to asdf for loading different versions of node (and others) and it solved my problem. Start up times are super fast now. |
It's a alright approach don't get me wrong. But the idea is premised on running Unfortunately (?) So use this if it works for y'allz particular needs. No 'dis on the on the perf improvement if you figure you'll only ever call |
This solution works for me and do speedup my WSL, thank you! I pick the function from your bashrc, anyone else could just paste them into your own to let it go.
|
@z1yuan I did something similar, but there's no reason to source the nvm script separately each time. Here's an alternative script; it's just as effective at speeding up your computer, and you still get bash-completion even before the command references the real nvm! Note: I'm not sure if you actually need to have
|
@SliceThePi I have tesed your script by adding them to my .bashrc. It speed up for sure, but it seems like i have to execute nvm to active it again, is it the same result as mines? Do you mean with your script we can speed up and active nvm/npm/node by default?
|
@z1yuan Yeah, I noticed that. I ended up adding the same thing for node, and a separate load_nvm thing
It's still not perfect (doesn't automatically get global node cli stuff into your PATH if I recall correctly) but it gets the job done a little better. |
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
`head -n 300 strace.out |tail -n 40` # to see context around line 288
Also, though you probably all figured this out already:
The TL;DR Here's what I ultimately came up with: set path, etc. to a default node version then lazy load # (updated .bashrc)
# Utility for removing an entry from $PATH -- copied from SO post:
# https://stackoverflow.com/questions/11650840/remove-redundant-paths-from-path-variable#answer-47159781
pathremove() {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
export NVM_DIR="$HOME/.nvm"
DEFAULT_NODE_VERSION="v12.10.0"
load_nvm() {
# TODO: ionice -c 1 -n 0 nice -n -20 cmd... ?
[ -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
}
#load_nvm
# This gets node & friends into the path but doesn't initialize nvm proper until needed
lasy_load_nvm() {
export NVM_BIN="$NVM_DIR/versions/node/$DEFAULT_NODE_VERSION/bin"
export PATH="$NVM_BIN:$PATH"
export NVM_CD_FLAGS=""
alias nvm="echo 'Please wait while nvm loads' && unset NVM_CD_FLAGS && pathremove $NVM_BIN && unset NVM_BIN && unalias nvm && load_nvm && nvm $@"
}
lasy_load_nvm So now, just after logging in, we can do this (assuming
|
Switched to "n" and experiencing a noticeable speed increase when opening all new terminals. |
Over the last 4 years of using my WSL instance, I've noticed this slow-down and attributed it to two things, one of which is the NVM environment. The other was my key-store, and was taking longer than 30 seconds to load. Debugging that highlighted a more generic problem: WSL does not have This highlights a bigger issue - none of the normal tmpfs mounts have been configured, so slow downs and storage leaks are likely, and this could be why NVM has slowed over the years. Granted, The lazy-load approach highlighted by @jacobq could be the best resolution for NVM, but it's only a patch hiding the real cause, whether that be a missing tmpfs mount or some other overlooked but fundamental part of *nix environments. |
Remove ~/.nvm all installed. |
Nice suggestion, but having tried this, I've found it has quite the knock on consequences:
|
@xploSEoF Sorry about that, I just tested it in my git bash shell in window. |
Describe
It is too slow to startup a new bash shell, 10sec or so, with following 2 lines at the bottom of .bashrc:
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
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash
OS version,etc.
system:14393 win10 pro x64
hardware: Intel i5 2.5GHz, 6GB RAM, 256GB SSD
The text was updated successfully, but these errors were encountered: