oh-my-zsh very slow (load time about 10 seconds)
Asked Answered
I

5

7

I am using:

Mac OS X 10.10.5 (Yosemite)
zsh 5.0.5
oh-my-zsh

the problem is, terminal load time is too slow about 10 seconds, even for opening new terminal tabs.

I tried solution on this blog post: http://osxdaily.com/2010/05/06/speed-up-a-slow-terminal-by-clearing-log-files/ but that didn't helped me.

sudo rm -rf /private/var/log/asl/*.asl

Thanks

Induline answered 25/11, 2016 at 5:33 Comment(1)
So, did you find any solution??Bijouterie
I
13

node was making trouble for me, and here is the solution that works:

In my .zshrc

# configure node version manager
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" --no-use # This loads nvm
alias node='unalias node ; unalias npm ; nvm use default ; node $@'
alias npm='unalias node ; unalias npm ; nvm use default ; npm $@'

For more information visit this Github issue.

Induline answered 25/11, 2016 at 5:42 Comment(0)
C
2

Please comment all the git prompt code in your theme.

zsh on my mac was very slow. Any command, like cd, ls took 2-5 seconds, but after I commented on all the git prompt code in the theme, things become totally different.

Enjoy the smooth again!

Contessacontest answered 6/10, 2017 at 23:45 Comment(1)
# plugins=(git) commenting this line makes a difference, thanksInduline
N
2

These are the steps which I have used to optimize my shell startup speed and reducing lag in executing commands -

  1. If you are using powerlevel9k, then I will recommend to immediately switch to powerlevel10k.

Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience. It is a reimplementation of the popular Powerlevel9k zsh theme. It looks exactly the same given the same configuration but renders prompt 10-100 times faster. It's optimized on every level of the stack, all the way down to using a patched version of libgit2 that can scan a repo 4 times faster than the original. It can remove Zsh startup lag even if it's not caused by a theme with features such as Instant Prompt.

  1. Go to Preferences -> Profiles -> General -> Command and select the option Command instead of Login Shell and paste the below command in the box nearby it.
login -pfq username /usr/local/bin/zsh -il

You wouldn't see the last login time printed when starting a new tab now. If zsh is not present in the location /usr/local/bin/zsh, you will need to install zsh using brew. The default zsh provided by mac is at /usr/bin/zsh and might be using an older version like 5.2 which can cause slow speed when used with iTerm or oh-my-zsh.

  1. To make pasting in zsh fast, execute the below command in the terminal.
mkdir -p $ZSH_CUSTOM/lib && touch $ZSH_CUSTOM/lib/misc.zsh
  1. Point 2 should already take care of slow login times. But just for safety execute the below command
mkdir -p .hushlogin
  1. There are tons of plugins you might be using which are slow and creates lag. You need to point out these plugins and remove them. For this, you will need zsh profiling. Follow this link for more details -

https://stevenvanbael.com/profiling-zsh-startup

Nubilous answered 28/3, 2020 at 6:18 Comment(0)
A
0

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.

Algetic answered 21/5, 2020 at 13:46 Comment(1)
something to note here is that the MAX_HISTORY is the number of lines to keep in history and not the number of commands.Algetic
S
0

The issue for me was that the Angular CLI autocompletions slowed down the loading. To disable this, comment the corresponding line in .zshrc:

# Load Angular CLI autocompletion.
# source <(ng completion script)
Slavism answered 13/6 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.