8

I'm using Z shell inside iTerm2 every time I open up a new window or a new tab it takes around 8 - 9 seconds to load.

I found some information on how to debug zsh. I came across this Speeding Up My Shell also I've found a script on SPEEDING UP ZSH AND OH-MY-ZSH.

Running the script I get this

╰─❯ for i in $(seq 1 10); do /usr/bin/time /bin/zsh -i -c exit; done
        1.56 real         0.76 user         0.47 sys
        1.30 real         0.74 user         0.44 sys
        1.31 real         0.74 user         0.44 sys
        1.30 real         0.74 user         0.44 sys
        1.31 real         0.74 user         0.44 sys
        1.31 real         0.74 user         0.44 sys
        1.30 real         0.74 user         0.44 sys
        1.29 real         0.74 user         0.44 sys
        1.31 real         0.75 user         0.44 sys
        1.31 real         0.74 user         0.44 sys

I'm using the antigen plugin.

Any idea what is adding another 5 - 6 seconds. How can I debug this?

9
  • I would rename all your startup zsh files so you have none, then add the command you need back one by one
    – mmmmmm
    Feb 24, 2022 at 17:48
  • @mmmmmm Thanks for responding. I've commented out everything in my ~/.zshrc file. Then restarted the OS (just in case something is cached). I'm still getting 8 seconds on new window and new tab.
    – Yuri Gurin
    Feb 24, 2022 at 17:58
  • 1
    and ~/.zshenv and ~/.zprofile and ~/.zlogin ? Ans what is the command called by iTerm, does Terminal.app show the same?
    – mmmmmm
    Feb 24, 2022 at 18:03
  • @mmmmmm when I open the Terminal.app I can see its switching between bash -> systemctl -> uname in a loop see here
    – Yuri Gurin
    Feb 24, 2022 at 18:35
  • 1
    @YuriGurin Obviously, you have not, as is obvious from your MP4. Remove everything you have added to the startup, or move them elsewhere. Feb 25, 2022 at 19:54

1 Answer 1

8

I have found the problem. The issue was not directly related to .zshrc as commenting out the entire file gave me the same results. It was clear to me that the issue was happening before .zshrc was loaded. My advice to anybody with a zsh issue look at all the components of zsh. From the article my guess is it was either .zlogin or .zprofile. zlogin was empty whereas .zprofile had over 2000 lines of eval "$(/opt/homebrew/bin/brew shellenv)". Deleting everything in .zprofile fixed the issue for me, however moments later duplicate commands have again reappeared. In my .zshrc the issue was this:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[your-user-name]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

which I have replaced with

#echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[your-user-name]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"

I have no idea why homebrew had this config in my .zshrc file, however, I have come across other users that have had this issue see https://github.com/Homebrew/discussions/discussions/446#discussioncomment-1084000

2
  • Very nice find. Any chance you can document the startup times on your Mac after fixing / optimizing the dot files?
    – bmike
    Mar 1, 2022 at 17:25
  • I've been struggling with this issue for so many years, and after a new attempt at solving this I came across your finding. I cannot believe how weird this issue is, but thanks! Sep 23 at 0:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .