I know this is a very old question but I tried all previous answers and the problem came back after some time. I did as much as to git rid of oh-my-zsh completely. But the actual culprit was .zsh-history. My history file was holding more than 1000 commands and was slowing down zsh. After clearing it zsh went from loading in 10 seconds to 3 seconds.
Here is a simple script to do this automatically.
HISTORY="~/.zsh-history" # Path to zsh history file
HISTORY_LOG="path/to/where/you/wan't/to/save/history"
MAX_HISTORY=100 # Maximum lines to keep in history
if [[ $(expr $(wc -l < $HISTORY) \> $MAX_HISTORY) = "1" ]]; then
cat $HISTORY >> $HISTORY_LOG && echo '' > $HISTORY
fi
Add this script to run on startup and it will clear out your history when it reaches over 100 lines. I save it to another location in case I wan't to find something in it later.
You could also change the script to always keep 100 lines in your history. That is to remove the first n lines so as to keep the number of lines 100. But I personally like this approach better.