Speedup zsh startup time

2

1

I'm on MacOS 10.11. When I open a new tab on Iterm2, it takes almost 2 second to have the prompt. So I guess I have something in .zshrc / .bash_profile / .bashrc that takes times to load. Here are those files :

.zshrc

export ZSH=/Users/ThomasDehaeze/.oh-my-zsh
ZSH_THEME="cobalt2"
plugins=(brew extract z sudo zsh-syntax-highlighting colored-man-pages web-search)
export PATH="$PATH:/Users/ThomasDehaeze/.rvm/gems/ruby-2.2.1/bin:/Users/ThomasDehaeze/.rvm/gems/ruby-2.2.1@global/bin:/Users/ThomasDehaeze/.rvm/rubies/ruby-2.2.1/bin:/usr/local/share/npm/bin:/usr/local/share/python:/Users/ThomasDehaeze/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ThomasDehaeze/.rvm/bin:/Users/ThomasDehaeze/miniconda3/bin:/Users/ThomasDehaeze/bin"

export ZSH_THEME_GIT_PROMPT_STASHED
export PATH=/Library/TeX/texbin:$PATH
export PATH=/opt/apache-maven-3.3.9/bin:$PATH
export VISUAL=vim
export EDITOR="$VISUAL"

source $ZSH/oh-my-zsh.sh
source ~/.git-flow-completion.zsh

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

export PATH="/usr/local/sbin:$PATH"

export NVM_DIR="/Users/ThomasDehaeze/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

.bash_profile

PATH=/usr/local/bin:$PATH
PATH=$HOME/bin:$PATH
export PATH
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
  [ -r "$file" ] && source "$file"
done
unset file
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
source /usr/local/opt/autoenv/activate.sh

.bashrc

export PIP_REQUIRE_VIRTUALENV=true
export PATH="$PATH:$HOME/.rvm/bin"

My guess is that mvn/npm are loaded to many times. Can you confirm that ? What path should I include and where ?

Thank you very much :)

Thomas Dehaeze

Posted 2016-06-16T08:39:55.940

Reputation: 121

You could try to do a time source ~/.zshrc; time source ~/.bash_profile to see how long they take. Afterwards you could try the same for each line in the file until you find the culprit. – Mikael Kjær – 2016-06-16T08:47:20.983

@MikaelKjær How to get the output of time command ? – Thomas Dehaeze – 2016-06-16T09:12:00.347

Doesn't it output it in your terminal? – Mikael Kjær – 2016-06-16T09:15:21.703

No, it takes time to run and then nothing... http://img15.hostingpics.net/pics/927260Capturedecran20160616112435.png

– Thomas Dehaeze – 2016-06-16T09:25:10.230

How strange. Try in bash. You can change by writing bash – Mikael Kjær – 2016-06-16T10:01:10.150

Thanks @MikaelKjær, this is what i get : real 0m1.527s

user 0m0.679s

sys 0m0.481s – Thomas Dehaeze – 2016-06-16T12:36:39.447

@MikaelKjær After some tests, I figure out that it was nvm that is slowing done the startup of zsh. This line : [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm. How can I remove this line and still using nvm from time to time ? (like load it manually) – Thomas Dehaeze – 2016-06-17T08:48:15.700

Finally found a workaround : https://github.com/creationix/nvm/issues/781

– Thomas Dehaeze – 2016-06-17T09:04:34.313

Answers

0

Try this command: nvm unalias default. Then restart your terminal.

Caveat: Now you'll have to launch nvm use <version> before using node.

Source: https://github.com/creationix/nvm/issues/703#issuecomment-145917599.

Geekarist

Posted 2016-06-16T08:39:55.940

Reputation: 409