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

oh-my-zsh very slow :( #5327

Closed
SebTM opened this issue Aug 20, 2016 · 71 comments
Closed

oh-my-zsh very slow :( #5327

SebTM opened this issue Aug 20, 2016 · 71 comments

Comments

@SebTM
Copy link

@SebTM SebTM commented Aug 20, 2016

Hello,

I'm new to zsh/oh-my-zsh and installed it the first time on Mac OS X today. My Terminal (iTerm2 and default Mac-Terminal) starts very slow now - I have a real "waiting" time after opening App. Inside the Terminal it's better but also compared to "default bash" - slow. For example, if I only push the enter-key it just takes 1-2 seconds before terminal "responds", or if I press "CMD+V" for paste, I have to wait some seconds.

Used software:

  • Mac OS X - 10.11.6 (El Capitan)
  • ZSH v5.2
  • oh-my-zsh - latest (installed today)

Benchmark (with plugins - see .zshrc - loaded):

/usr/bin/time /usr/local/bin/zsh -i -c exit
4.63 real 0.47 user 0.29 sys

Benachmark (without plugins loaded):

/usr/bin/time /usr/local/bin/zsh -i -c exit
1.38 real 0.24 user 0.13 sys

Here also my ".zshrc"-file:

# Path to your oh-my-zsh installation.
export ZSH=/Users/username/.oh-my-zsh

# Set name of the theme to load.
ZSH_THEME="agnoster"

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
plugins=(git command-not-found copydir copyfile cp history sublime vagrant composer symfony brew osx)

source $ZSH/oh-my-zsh.sh

# Set default-user to remove "user@hostname" from agnoster
DEFAULT_USER="username"

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

# Set correct path for php-5.6
export PATH=/usr/local/php5-5.6.23-20160626-132038/bin:~/.composer/vendor/bin/:$PATH

Is this normal or can it be fixed?

@mcornella
Copy link
Member

@mcornella mcornella commented Aug 20, 2016

Try running zsh in debug mode: zsh -xv and note where in the terminal freezes. If you use the asciinema tool you'll be able to record it in real time and post it here. asciinema isn't able to record time, it all just looks like a sequencial log with no pauses.

@SebTM
Copy link
Author

@SebTM SebTM commented Aug 20, 2016

Thanks for your fast reply. I figured out, that "command-not-found" really slows down the start of zsh (on opening new shell), so I removed it as it does not have this overvalue. I also found out, that there is a difference running zsh "normaly" or after sourcing the .zshrc. It takes about double time after resourcing the file.

You cann see the asciinema-video here: https://asciinema.org/a/9h3kd6ngpxnosmdi5ra3totgc

@allanburleson
Copy link

@allanburleson allanburleson commented Aug 21, 2016

I believe you want to close this if you figured out the problem?

@SebTM
Copy link
Author

@SebTM SebTM commented Aug 21, 2016

Hmm, not really as it is still slow. What do you say to the benchmark time without plugins? Is it normal?

What about the fact, that benchmark takes double time after sourcing ".zshrc"?

@eduOS
Copy link

@eduOS eduOS commented Aug 31, 2016

Mine is very very slow. When I open a terminal it takes about 7 seconds to launch the zsh and sometimes only half of the theme can display. What's wrong with it after several updates?

@cewood
Copy link

@cewood cewood commented Sep 7, 2016

I'm experiencing a similarly slow startup time to what @eduOS describes, 6-7 seconds to have a usable terminal 👎

@yorch
Copy link

@yorch yorch commented Sep 8, 2016

Cleaning the ASL logs (as described here) helps to reduce the startup time

@foxx
Copy link

@foxx foxx commented Sep 22, 2016

Turns out my slowness was due to nvm being loaded on this line;

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

I fixed this by using the following alias, and running loadnvm whenever I need it.

alias loadnvm=". /usr/local/opt/nvm/nvm.sh"

(thank you @mcornella for pointing out debug switches, doh!)

@SebTM
Copy link
Author

@SebTM SebTM commented Sep 22, 2016

So is it fixed - or how can I fix it on my device?

@foxx
Copy link

@foxx foxx commented Sep 22, 2016

@SebTM can you paste a copy of your .zshrc please? Also can you try with a clean .zshrc and then also with a fresh install of ohmyzsh? This should at least help narrow down where the problem might be

@nicohvi
Copy link

@nicohvi nicohvi commented Sep 29, 2016

This might be unrelated, but I'm seeing the same on a fresh install of ohmysh on Ubuntu on Windows 10. Works like a charm on my OS X install btw, great job 👍

Zsh-version: 5.0.2
Ohmyzsh-version: latest

This is the entire content of my .zshrc:

ZSH=/home/<username>/.oh-my-zsh
source $ZSH/oh-my-zsh.sh

The shell takes about 7 seconds to load whenever I source ohmysh.sh.

Update
After doing some more research, it's the sourcing of config files that takes so long.

for config_file ($ZSH/lib/*.zsh);do
  custom_config_file="${ZSH_CUSTOM}/lib/${config_file:t}"
  [ -f "${custom_config_file" ] && config_file="${custom_config_file}
  source $config_file # this takes about six seconds
done

Update 2
It seems history.zsh might be the culprit. When I remove it from the lib folder the boot time goes down to about 2 seconds (which I can live with).

@ShawnLinLoveLife
Copy link

@ShawnLinLoveLife ShawnLinLoveLife commented Oct 7, 2016

# Path to your oh-my-zsh installation.
export ZSH=/Users/shawn/.oh-my-zsh

ZSH_THEME="agnoster"

plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
. /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh

This is my zshrc, and I think it is the last line that makes it slowly. Any suggestions? Thanks!

. /usr/local/lib/python2.7/site-packages/powerline/bindings/zsh/powerline.zsh
@mcornella
Copy link
Member

@mcornella mcornella commented Oct 10, 2016

@mcornella
Copy link
Member

@mcornella mcornella commented Oct 10, 2016

@nicohvi can you try debugging where in the file it slows down? If you run set -xv; source $ZSH/lib/history.zsh; set +xv you'll get the whole trace.

Pay attention to the particular line where it stops, if it stops at all.

@mcornella
Copy link
Member

@mcornella mcornella commented Oct 10, 2016

@SebTM the asciinema video doesn't capture terminal pauses... You can try disabling plugins one by one and checking the load time with your custom command.

@nicohvi
Copy link

@nicohvi nicohvi commented Oct 10, 2016

Sure thing @mcornella 👍

@NauxChen
Copy link

@NauxChen NauxChen commented Nov 1, 2016

zsh -xv > ~/info 2>&1
@austenLacy
Copy link

@austenLacy austenLacy commented Nov 3, 2016

@nicohvi I also found that it was caused by the history.zsh file. I updated lines

HISTSIZE=10000
SAVEHIST=10000

to only be

HISTSIZE=1000
SAVEHIST=1000

It seems that the issue was that my .zsh_history file was almost 50k lines long with previous commands. Deleting that file also did the trick, though you'll lose all command history you've had.

@chefjuanpi
Copy link

@chefjuanpi chefjuanpi commented Nov 3, 2016

I have the same insue with zsh in ubuntu in vagrant in a win 10 machine.

I install zsh and oh my zsh today is a really fresh installation.

all works fine out the project folder. with debug mode appears that:

+prompt_git:11> dirty=+prompt_git:11> parse_git_dirty
+parse_git_dirty:1> local 'STATUS='
+parse_git_dirty:2> local FLAGS
+parse_git_dirty:3> FLAGS=( --porcelain )
+parse_git_dirty:4> [[+parse_git_dirty:4> git config --get oh-my-zsh.hide-dirty
+parse_git_dirty:4> [[ '' != 1 ]]
+parse_git_dirty:5> [[ 1 -gt 0 ]]
+parse_git_dirty:6> FLAGS+='--ignore-submodules=dirty'
+parse_git_dirty:8> [[ '' == true ]]
+parse_git_dirty:11> STATUS=+parse_git_dirty:11> STATUS=+parse_git_dirty:11> git status --porcelain '--ignore-submodules=dirty'
+parse_git_dirty:11> tail -n1

and frezze the screem more less 30 sec.

I try to change agnoster to robbyrussell but the problem continue

@przbadu
Copy link

@przbadu przbadu commented Nov 25, 2016

@foxx Thanks man, I was going crazy with this problem, mine was almost taking 8-10 seconds to load terminal and new tabs and finally creating alias to manually load nvm and removing old lines worked for me

Small tips though, looking at the auto generated code we can also use $(brew --prefix nvm)/nvm.sh

# export NVM_DIR=~/.nvm
# source $(brew --prefix nvm)/nvm.sh
alias loadnvm=". $(brew --prefix nvm)/nvm.sh"

This did fixed my problem with load time, thanks

@gerardbm
Copy link

@gerardbm gerardbm commented Nov 30, 2016

I had the same problem in my terminal. As a GNU/Linux user, I removed these two lines from the file .zprofile:

export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh

I needed them to use jshint on Sublime Text. Recently I switched to Neovim, so I can remove them.

Now the load time is about 2 seconds.

@9mm
Copy link

@9mm 9mm commented Dec 15, 2016

Heres a better solution that still lets you call node and npm:

nvm-sh/nvm#539 (comment)

@lu4
Copy link

@lu4 lu4 commented Jan 25, 2017

@samkugji you've killed the thread with your green mile, cut the crap

@sprig
Copy link

@sprig sprig commented Jan 26, 2017

I used a profiling function and found out that 'spectrum.zsh' was taking (in the profiler, which runs slower - but still) several seconds. I replaced it temporarily with an empty file and the startup got much faster (still too slow - IMHO it shouldn't take over half a second - but at least bearable).

@9mm
Copy link

@9mm 9mm commented Jan 26, 2017

@sprig
Copy link

@sprig sprig commented Jan 26, 2017

I don't know. It doesn't seem essential (read the code). it's in $oh-my/lib/spectrum.zsh

@RWOverdijk
Copy link

@RWOverdijk RWOverdijk commented Mar 3, 2017

Slow here as well. I found most of it to be caused by nvm, too.

@T0mK0
Copy link
Contributor

@T0mK0 T0mK0 commented Mar 15, 2017

If you use aws plugin , comment out brew invocation in :

.oh-my-zsh/plugins/aws/aws.plugin.zsh

_awscli-homebrew-installed() {
#  brew list awscli &> /dev/null
 true
} 

AND add false to

_homebrew-installed() {
  type brew &> /dev/null
  false
}

So even if you have brew installed ( probably good idea anyway ) , you will save 2 invocations of

brew --prefix awscli
and
brew list awscli

$ time zsh -xv -c exit
exit
+zsh:1> exit
zsh -xv -c exit  0.00s user 0.00s system 55% cpu 0.006 total

My plugins

plugins=(zsh-autosuggestions brew aws kitchen knife osx ruby docker colorize vagrant zsh-syntax-highlighting sudo)
@zongwu233
Copy link

@zongwu233 zongwu233 commented Jan 4, 2018

Thanks to @tabair-addepar
I find 'curl --silent --location --connect-timeout 7 --max-time 10 https://api.sdkman.io/2/candidates/all ' wait for 7 second in the debug log.
I reduce timeout config ,That OK.
And another one is

0.000015 +prompt_end:1> [[ -n blue ]]
0.000009 +prompt_end:2> echo -n ' %{%k%F{blue}%}⮀'
0.000010 +prompt_end:6> echo -n '%{%f%}'
0.000009 +prompt_end:7> CURRENT_BG=''
3.963591 ^[[?1h^[=+_main_complete:11> local 'IFS=
0.000091 ^@'
@eromoe
Copy link

@eromoe eromoe commented Jan 11, 2018

This line is super slow in my windows 7 msys2 env

+git_prompt_info:2> [[+git_prompt_info:2> git config --get oh-my-zsh.hide-status

But I have already disable git

plugins=(
  #git
  zsh-autosuggestions
)

What should I do ?

@eromoe
Copy link

@eromoe eromoe commented Jan 11, 2018

I find the solution if git_prompt_info slow

git config --global oh-my-zsh.hide-status 1
  1. disable that function in ~/.zshrc
git_prompt_info() {}
@revolter
Copy link
Contributor

@revolter revolter commented Feb 10, 2018

If I have

0.000022 +prompt_char:16> echo -n '%(!.%F{red}#.%F{green}>%f)'
38.914652 �[?1h�=�[?1l�>nvim zsh_startup.log

does this mean that echo took 0.38 seconds?

@tabair-addepar
Copy link

@tabair-addepar tabair-addepar commented Feb 12, 2018

@revolter Umm... I think that means echo took almost 39 seconds. Which is very odd. Can you show us the command you entered to generate your startup log? If we're lucky, there's just something odd about how you generated the log. If not, that's kind of a head scratcher.

@revolter
Copy link
Contributor

@revolter revolter commented Feb 12, 2018

@tabair-addepar, I just ran zsh -xv 2>&1 | ts -i "%.s" > zsh_startup.log from your comment.

I now get:

0.000037 +prompt_char:16> echo -n '%(!.%F{red}#.%F{green}>%f)'
5.827991 �[?1h�=�[?1l�>nvim zsh_startup.log
...
0.000027 +prompt_char:16> echo -n '%(!.%F{red}#.%F{green}>%f)'
3.305347 �[?1h�=�[?1l�>nvim zsh_startup.log
@tabair-addepar
Copy link

@tabair-addepar tabair-addepar commented Feb 14, 2018

Well, I think we're both doubtful that echo is actually taking that long to execute. That "+prompt_char:16" means that you're one subshell deep, and, I think, inside a function or script named "prompt_char". That's probably the function that sets your command prompt or maybe it's even as simple as a function that's deciding what the last character of your prompt should be based on what your UID is.

If that function had some logic in it that was responsible for the delay, that would show up in this log as the offending line instead of this echo. Since I see what appears to be a prompt getting printed on the "nvim" line, that delay could be caused by your prompt_cmd that runs before each prompt is printed. Maybe prompt_cmd isn't being caught in the log for some reason?

Can I see a full log? Perhaps there's more telling info in there somewhere.

@wzrdtales
Copy link

@wzrdtales wzrdtales commented Mar 12, 2018

For the nvm issues, I had the same, just entered what I am using all the time as a plugin #6671

@maths-lover
Copy link

@maths-lover maths-lover commented Apr 28, 2018

What I did worked for reducing time consumption at initial startup.

What I did is that, I edited oh-my-zsh.sh in .oh-my-zsh folder and commented the all the lines which check for updates.
i.e., these lines
Check for updates on initial load...
#if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
# env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh
#fi

and the terminal initialises right at the startup without any time

@jesstelford
Copy link

@jesstelford jesstelford commented May 4, 2018

I knocked off about 3s, using this script by @Tyriar & @Stanzilla to defer loading of nvm:

# Defer initialization of nvm until nvm, node or a node-dependent command is
# run. Ensure this block is only run once if .bashrc gets sourced multiple times
# by checking whether __init_nvm is a function.
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(whence -w __init_nvm)" = function ]; then
  export NVM_DIR="$HOME/.nvm"
  [ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
  declare -a __node_commands=('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack')
  function __init_nvm() {
    for i in "${__node_commands[@]}"; do unalias $i; done
    . "$NVM_DIR"/nvm.sh
    unset __node_commands
    unset -f __init_nvm
  }
  for i in "${__node_commands[@]}"; do alias $i='__init_nvm && '$i; done
fi

Make sure you also remove nvm from the plugins list, and remove any other NVM loading code.

This has the benefit of auto-loading nvm the first time you try to run any of the commands in ('nvm' 'node' 'npm' 'yarn' 'gulp' 'grunt' 'webpack') 🎉

@skoskie
Copy link

@skoskie skoskie commented May 7, 2018

The script referenced directly above made the biggest difference for me. After trying everything else in this thread, I still had a 6.9 second load time because I was loading the zsh plugins that depended on nvm, so loading of nvm wasn't really delayed.

Adding this script and removing the relevant zsh plugins reduced the time from 6.9 seconds to 1.2 seconds.

And as you might expect, executing npm or one of the other commands for the first time takes a little longer, but that's a perfectly acceptable trade-off.

@wzrdtales
Copy link

@wzrdtales wzrdtales commented May 7, 2018

yup lazy loading is also a way to do it, but it might still screw with your performance. For example if you use neovim or other editors with certain extensions. Basically everything that spawns a new shell will suck :/ . Apart from that it should work, for me my hard fork works just perfect and has also eliminated almost all the overhead and loadtime which have been the problem.

https://github.com/wzrdtales/nvm-ng

Small benchmarks of the improvement are here:

wzrdtales/nvm-ng#2

and load it with (the --fast-reuse bit makes the biggest improvement though)

[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" --fast-reuse

Or just manually pull the plugin #6671 and use it.

It is still very sad that the author of nvm is not really willing to replace the very slow npm call which is the reason of all evil with a simple sed. However. all the solutions here should help.

@partounian
Copy link
Contributor

@partounian partounian commented Aug 29, 2018

There's also this zsh plugin for nvm which I have been using for some time https://github.com/lukechilds/zsh-nvm

@addozhang
Copy link

@addozhang addozhang commented Sep 29, 2018

I disable the oc, kubectl, docker plugin and comment the initialization of nvm and sdkman.

Additionally, switch command of Default profile from Login shell to Command with /usr/bin/login -pfq xxx filled. xxx is your username.

It runs fast now.

@endlesslight0
Copy link

@endlesslight0 endlesslight0 commented Oct 25, 2018

My zsh was starting about 10 seconds. After manual upgrade_oh_my_zsh it now flies !

@Tsovak
Copy link

@Tsovak Tsovak commented Jan 19, 2019

brew install moreutils
call zsh -xv 2>&1 | ts -i "%.s" > zsh_startup.log
sort by time sort --field-separator=' ' -r -k1 zsh_startup.log> sorted.log
and see what loaded too slow. For me, it was a ruby plugin which needs a 3 second to loads

@tayyarg
Copy link

@tayyarg tayyarg commented Jan 22, 2019

The issue in my case was the vcs_info which checks the version control status of the current working directory.

1- I've replaced the following line in my active theme redefined.sh-theme under .oh-my-zsh/themes folder:

command git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ] && echo "*"

to

git diff-files --no-ext-diff --quiet || git diff-index --no-ext-diff --quiet --cached HEAD

(This is only good unless you want to take untracked files into account)

2- Set the DISABLE_UNTRACKED_FILES_DIRTY="true" in my .zshrc
3- Ran git config oh-my-zsh.hide-status 1 on the most complicated repo I'd visit at most

By the way, thanks guys for pointing out, zsh -xv helped me a lot to find the problematic line.

Now, switching into folders with complicated repos is much faster.

@travisstaloch
Copy link

@travisstaloch travisstaloch commented May 14, 2019

If you are using powerlevel9k, make the switch to powerlevel10k which is MUCH faster. I noticed a big speedup from wsl ubuntu 18.04 after switching from 9k to 10k.

@Red-Eyed
Copy link

@Red-Eyed Red-Eyed commented May 30, 2019

Hello, same issue. it runs about 10 second and ~6 seconds for each command.
Commenting all in .oh-my-zsh/lib/history.zsh fixed that.

@yaochx
Copy link

@yaochx yaochx commented Jun 20, 2019

I met the same issue, there were xcode 9.0 and xcode 8.2 in my osx.
once openning iterm2, the title bar occured (xcodebuild), so I uninstall xcode 8.2.
Luckily, it works fine

@tasomaniac
Copy link

@tasomaniac tasomaniac commented Nov 13, 2019

command-not-found is really really slow to init.

@wrabit
Copy link

@wrabit wrabit commented Apr 7, 2020

Hitting ctrl+c and it hangs for while until it terminates the current operation, even if there is nothing to terminate.

Update a mixture of #5327 (comment) and simply git adding and committing my project solved my issue.

@Sunwarul
Copy link

@Sunwarul Sunwarul commented Apr 22, 2020

Turns out my slowness was due to nvm being loaded on this line;

export NVM_DIR="$HOME/.nvm"
. "$(brew --prefix nvm)/nvm.sh"

I fixed this by using the following alias, and running loadnvm whenever I need it.

alias loadnvm=". /usr/local/opt/nvm/nvm.sh"

(thank you @mcornella for pointing out debug switches, doh!)

Thanks, man. This Worked for me. NVM script was taking some time to loaded.

@mcornella
Copy link
Member

@mcornella mcornella commented May 11, 2020

@ahmadie
Copy link

@ahmadie ahmadie commented Nov 16, 2020

nvm is slow to load and was mading me crazy when i switch to zsh,
alias loadnvm=". /usr/local/opt/nvm/nvm.sh"
fixed the problem though !!

@scratchoo
Copy link

@scratchoo scratchoo commented Feb 9, 2021

oh-my-zsh is slow on folders with git while fast in other regular folders, we got rid of this issue using:

git config oh-my-zsh.hide-status 1 --global

this will disable the Git status prompt in all repositories you have on your machine

Now if I do something like ls the output is immediate, it's unfortunate to not see the git status but a fast terminal is more important than this :)

source of the command above: https://www.stevenrombauts.be/2018/04/disable-git-prompt-in-oh-my-zsh/ (thanks to the author)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet