26

I'm using OS X 10.8 and lately I'm noticing that iTerm2 can sometimes be quite slow with opening a new shell. It takes around 5 seconds before I can do something. Might not seem a lot, but I work a lot in the shell so it can get pretty annoying.

I'm using ZSH with oh-my-zsh.

I've tried Terminal, uninstalling oh-my-zsh, clearing everything unnecessary from the startup files (.zshenv, .zlogin, .zprofile, .zshrc, .zlogout) and clearing the ASL-files in /var/log/asl and although it goes down a bit (like 0.20s), there's nothing that brings it down to pretty instantaneous or even below 3.0s.

Does anyone happen to have another idea?

Dimitri
  • 361

3 Answers3

32

Clear log in /var/log/asl, i.e.,

rm -rf /var/log/asl/*.asl
neo
  • 740
19

Per comment from Archan Mishra above, for iTerm 2 the answer is to set up a custom terminal command /bin/bash -il which bypasses searching the system ASL logs completely. iterm2 opens instantly now.

DavidPostill
  • 162,382
David
  • 309
3

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