It's not a huge issue, but I find terminals take 1.5-2s to launch, which makes launching them feel sluggish.
gitpod ~ $ time bash --rcfile .bashrc -i -c 'true'
real 0m1.561s
user 0m0.481s
sys 0m1.330s
I suspect this is caused by all the .bashrc processing that bash does when it's launched.
gitpod ~ $ time bash --rcfile emptyfile -i -c 'true'
real 0m0.010s
user 0m0.003s
sys 0m0.010s
Adding set -x to .bashrc shows there's loads of setup going on, including npm config --loglevel=warn get prefix, and lots of python stuff.
In total, it looks like there must be over >1500 commands executed:
gitpod ~ $ bash --rcfile mybashrc -i -c 'true' 2>&1 | grep ^+ | wc -l
1541
Is all this .bashrc processing really necessary in all workspaces? It would improve the overall feeling of Gitpod if they launched more speedily.
Thanks a lot for reporting this annoying issue! I'll look into it this week to see what can be improved there.
(I suspect that some of our language managers can be blamed for much of this slowdown.)
@janx I also noticed that we have .bash_profile which apparently doesn't get executed at all?
Oh, interesting. Will look into that as well. (I think .bash_profile is something you're used to edit on Mac OS, but on Ubuntu you need to explicitly call that file from .bashrc if you want it to work.)
I added a bunch of timing logs to ~/.bashrc and ~/.bash_profile, and here are the results:
[bashrc] 07:24:26.589388361 top
[bashrc] 07:24:26.591662734 git configured
[bashrc] 07:24:26.608380544 gp completion
[bashrc] 07:24:26.610949965 checkwinsize
[bashrc] 07:24:26.618243901 color prompt
[bashrc] 07:24:26.623430538 bash aliases
[bashrc] 07:24:26.642250177 bash completion
[bashrc] 07:24:26.689532784 sdkman
[bashrc] 07:24:27.178797254 nvm
[bashrc] 07:24:27.343346377 pyenv
Conclusions:
~/.bash_profile is indeed never run489.26ms nvm
164.55ms pyenv
47.28ms sdkman
18.82ms bash completion
16.72ms gp completion
7.29ms color prompt
5.19ms bash aliases
2.57ms checkwinsize
2.27ms git configured
i.e. nvm, pyenv and sdkman together take more than half a second to initialize.
Ideally, we should initialize Terminals in <= 100ms to feel "instant".
Based on this Reddit comment, I was able to produce a lazy-loading nvm setup:
declare -a NODE_GLOBALS=(`find ~/.nvm/versions/node -maxdepth 3 -type l -wholename '*/bin/*' | xargs -n1 basename | sort | uniq`)
NODE_GLOBALS+=("node")
NODE_GLOBALS+=("nvm")
load_nvm () {
export NVM_DIR=~/.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
}
for cmd in "${NODE_GLOBALS[@]}"; do
eval "${cmd}(){ unset -f ${NODE_GLOBALS[@]}; load_nvm; ${cmd} \$@; }"
done
This now runs in ~18.83ms instead of ~489.26ms.
FYI, I've just merged the lazy-loaded nvm, which should be deployed to our Docker Hub images (e.g. gitpod/workspace-full) within 1 or 2 hours, and should become the default in all Gitpod workspaces with the next production release (hopefully this week or next week).
This takes Gitpod's Terminal initialization time from ~754ms down to ~283ms, a 2.7x speed-up! 馃帀
Most helpful comment
FYI, I've just merged the lazy-loaded
nvm, which should be deployed to our Docker Hub images (e.g.gitpod/workspace-full) within 1 or 2 hours, and should become the default in all Gitpod workspaces with the next production release (hopefully this week or next week).This takes Gitpod's Terminal initialization time from ~754ms down to ~283ms, a 2.7x speed-up! 馃帀