13

I recently got a new Retina MacBook Pro, with Mountain Lion. Unfortunately, emacs is taking forever to startup (around 5s) on my new computer. I tried installing the latest homebrew version of emacs, but the problem persists. I don't have a .emacs file, so I'm clueless as to what could be causing the slow startup.

What tools do I have at my disposal to debug where emacs is spending its time during startup?

Mike
  • 23,892
  • 18
  • 70
  • 90
  • You can also run `M-x emacs-init-time` to determine how long Emacs reads your init files (which should be 0 s if you start with `-Q`). Also, you may want to check out this [superior Emacs port](https://github.com/railwaycat/emacs-mac-port) for your Mac (it's much faster for flyspell, TRAMP, etc.). – jmdeldin Sep 06 '12 at 23:39
  • I get 0.0 seconds. Starting with `-Q` still yields a slow startup time. – Mike Sep 07 '12 at 17:03
  • Hmm...What's in the `*Messages*` buffer if you launch `emacs -Q --debug-init`? To clarify, are you running in console or with a GUI? – jmdeldin Sep 07 '12 at 20:47
  • This is going to sound crazy, but apparently [it happens to others](http://lists.gnu.org/archive/html/help-gnu-emacs/2011-09/msg00123.html): Does it start up slowly if you turn off wireless? Also, do you have a fully-qualified domain name set for your `hostname`, e.g., `myretina.local` ([related](http://web.cecs.pdx.edu/~akshay/2012/01/fix-emacs-slow-start-up-on-fedora-16/)? – jmdeldin Sep 07 '12 at 20:51
  • @jmdelin Thanks, that did the trick! `sudo scutil --set HostName mike.local` did the trick. If you write up an answer, I'll accept it. – Mike Sep 08 '12 at 19:55

6 Answers6

22

It looks like you need to have a fully-qualified domain name for your computer's hostname (e.g., myretina.local); otherwise, Emacs will be slow to start.

You can verify your hostname via Terminal with

hostname

and you can set it with

sudo scutil --set HostName myretina.local
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
jmdeldin
  • 5,354
  • 1
  • 28
  • 21
  • Worked for me. Running Lion, HostName was not set. Emacs very slow to start. Set HostName. Emacs instantly starts. Thanks. – etchasketch Sep 11 '12 at 07:51
4

For starters, run emacs -Q (which will start Emacs with no start-up files at all), and see whether that's still slow.

You may wish to read over the following, which explains all the various possible files which Emacs will look for by default:

C-hig (emacs) Init File RET

phils
  • 71,335
  • 11
  • 153
  • 198
  • 1
    `emacs -Q` is still slow. When I do C-h i g Init, I get (No Match), and can't type the space. – Mike Sep 07 '12 at 17:02
  • It seems that you didn't type the `(emacs)` part? Alternatively use `M-: (info "(emacs) Init File") RET`. However if `emacs -Q` is slow, reading about init files won't help. You might want to try http://emacsformacosx.com/ but that's the extent of my suggestions, sorry. – phils Sep 07 '12 at 23:09
2

Changing hostname didn't do anything for me. What worked wonders for me seems counter intuitive, but now my emacs starts instantly from terminal. This is what I did

alias emacs=/Applications/Emacs.app/Contents/MacOS/Emacs --debug-init

However, it still takes a few seconds, sometime even 15 seconds, to start from the graphical interface. Weird!

René Höhle
  • 26,716
  • 22
  • 73
  • 82
path4
  • 91
  • 1
  • 1
1

Emacs should start up instantaneously in your setup

Mac build (from sources)

% time /Applications/Emacs.app/Contents/MacOS/Emacs --debug-init -eval '(kill-emacs)' -Q
/Applications/Emacs.app/Contents/MacOS/Emacs --debug-init -eval '(kill-emacs)  0.19s user 0.06s system 35% cpu 0.696 total

NS build downloaded from emacsformacosx.com

% time /Volumes/Emacs/Emacs.app/Contents/MacOS/Emacs --debug-init -eval '(kill-emacs)' -Q
/Volumes/Emacs/Emacs.app/Contents/MacOS/Emacs --debug-init -eval  -Q  0.17s user 0.08s system 35% cpu 0.691 total

I don't use homebrew for Emacs but it should be similar. Are you sure you're not loading non-standard packages some how?

event_jr
  • 17,467
  • 4
  • 47
  • 62
0

There really is something totally broken with emacs. If nameservice collapses or routing is not fine, or your vpn tunnel is off, etc.

For us, sysadmins, starting vi is always an option:

# time emacs -debug-init -eval '(kill-emacs)' -Q

real    2m5.177s
user    0m0.029s
sys     0m0.024s

At this time the vpnc has died and caused some problems (routing and nameservice). Notice over 2 minutes!

After 30 years using emacs still do not understand why it really needs to resolve your hostname. For locking files there are better alternatives than that.

Managing hundreds/thousands of machines and VMs and setting individual host files is not really an answer. Manually it would take days/weeks and automatically generating. It really is as good as nothing.

armatita
  • 12,825
  • 8
  • 48
  • 49
0

Fixed by adding the local hostname and corresponding ip in /etc/hosts for me

Manuel Rozier
  • 677
  • 5
  • 9