Skip to content
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

Optimize ~/.bashrc.d/* loading time to make new terminals load faster #384

Open
jankeromnes opened this issue Apr 7, 2021 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jankeromnes
Copy link
Contributor

jankeromnes commented Apr 7, 2021

I added a few date -Ins into a ~/.bashrc on Gitpod, and found that loading all $HOME/.bashrc.d/* scripts:

(echo; echo "for i in \$(ls \$HOME/.bashrc.d/*); do source \$i; done"; echo) >> /home/gitpod/.bashrc

... can take 313ms (sample size = 1)


Adding a few more date -Ins showed me that the longest-running $HOME/.bashrc.d/* scripts could be:

&& { echo; \
echo 'eval "$(pyenv init -)"'; \
echo 'eval "$(pyenv virtualenv-init -)"'; } >> /home/gitpod/.bashrc.d/60-python \

... 109ms (sample size = 1)

&& echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*' >> /home/gitpod/.bashrc.d/70-ruby

... 116ms (sample size = 1)

@jankeromnes jankeromnes added enhancement New feature or request help wanted Extra attention is needed labels Apr 7, 2021
@jankeromnes jankeromnes changed the title Optimize ~/.bashrc.d/* loading time to make new terminals load faster Optimize ~/.bashrc.d/* loading time to make new Gitpod terminals load faster Apr 7, 2021
@jankeromnes jankeromnes changed the title Optimize ~/.bashrc.d/* loading time to make new Gitpod terminals load faster Optimize ~/.bashrc.d/* loading time to make new terminals load faster Apr 7, 2021
@axonasif
Copy link
Member

axonasif commented Dec 18, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants