Optimize ~/.bashrc.d/* loading time to make new terminals load faster
I added a few date -Ins into a ~/.bashrc on Gitpod, and found that loading all $HOME/.bashrc.d/* scripts:
https://github.com/gitpod-io/workspace-images/blob/baa144a3292c13a17d56f38d7f67653edd59daf2/base/Dockerfile#L54
... can take 313ms (sample size = 1)
Adding a few more date -Ins showed me that the longest-running $HOME/.bashrc.d/* scripts could be:
https://github.com/gitpod-io/workspace-images/blob/baa144a3292c13a17d56f38d7f67653edd59daf2/full/Dockerfile#L158-L160
... 109ms (sample size = 1)
https://github.com/gitpod-io/workspace-images/blob/baa144a3292c13a17d56f38d7f67653edd59daf2/full/Dockerfile#L188
... 116ms (sample size = 1)
~~Hi @jankeromnes! I could load everything in $HOME/.bashrc.d within just 0.001s with source $HOME/.bashrc.d/*. While this takes lot more cpu cycles and invocations of source command over the unnecessary for loop with ls, thus making it kinda slower~~ 😓
~~Here are some logs~~ 😄
gitpod /workspace/workspace-images $ time (for i in $(ls $HOME/.bashrc.d/*); do source $i; done)
real 0m0.197s
user 0m0.151s
sys 0m0.083s
gitpod /workspace/workspace-images $ time (source $HOME/.bashrc.d/*)
real 0m0.001s
user 0m0.000s
sys 0m0.001s
gitpod /workspace/workspace-images $ time (source $HOME/.bashrc.d/*)
real 0m0.001s
user 0m0.000s
sys 0m0.001s
gitpod /workspace/workspace-images $ time (for i in $(ls $HOME/.bashrc.d/*); do source $i; done)
real 0m0.239s
user 0m0.175s
sys 0m0.061s
gitpod /workspace/workspace-images $ time (for i in $(ls $HOME/.bashrc.d/*); do source $i; done)
real 0m0.209s
user 0m0.151s
sys 0m0.096s
gitpod /workspace/workspace-images $
Edit: Well nope, sorry, my bad. source only takes one filename at a time, missed that point.