24

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?

5
  • Related questions: 31403, 41743, 236953, 444614
    – Lri
    Nov 30, 2012 at 14:22
  • Have you tried changing the command for new shells to something like login -pfq username /usr/local/bin/zsh?
    – Lri
    Nov 30, 2012 at 14:23
  • @lauri-ranta: Tried everything in those other threads, but to no avail. Trying "login -pfq username /usr/local/bin/zsh" did nothing as well.
    – Dimitri
    Nov 30, 2012 at 15:53
  • To see if it is shell- or iTerm2 related: how much time does it take to start a new shell? (by entering zsh in an already open terminal window)?
    – Matteo
    Jan 5, 2013 at 16:13
  • add to .zshrc : [ $((RANDOM & 1)) -eq 0 ] && do not sleep 5
    – theoden8
    Aug 11, 2015 at 14:04

3 Answers 3

30

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

rm -rf /var/log/asl/*.asl
3
  • 4
    Could you explain WHY iterm is being slowed down by this log folder and is there anything that can be done to actually stop this problem from happening?
    – David
    Aug 11, 2014 at 19:56
  • 3
    @david you can check this link for understanding the reason why new tabs are slow. apple.stackexchange.com/a/71930/89583 Aug 11, 2015 at 5:17
  • 1
    Wow --- thank you so much --- for iterm2 it seems that the answer is to use the suggestion at the bottom of that page (/bin/bash -il ) from the guy who got downvoted to -1. Works great.
    – David
    Aug 11, 2015 at 13:58
18

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.

1
  • as I was also running oh-my-zsh. It told me to only use zsh. So /bin/zsh -il worked for me
    – azizbro
    Jul 9 at 0:57
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

2
  • Welcome to Super User! Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
    – DavidPostill
    Mar 28, 2020 at 7:13
  • after setting the command preferences it is asking for login everytime when opening new terminal or tabs. Is there anyway to fix this? Feb 20 at 8:54

You must log in to answer this question.

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