20

My emacs configuration takes a very long time to load. How can I easily find the offending parts and optimize them?

Phob
  • 891
  • 8
  • 13

3 Answers3

33

Very useful package: http://www.emacswiki.org/emacs/ProfileDotEmacs

Just skip loading your init file and let ProfileDotEmacs load/profile it for you:

emacs -Q -l profile-dotemacs.el -f profile-dotemacs
Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58
  • 2
    The wiki is a source of infinite wisdom for all things Emacs. – Noufal Ibrahim Apr 23 '11 at 05:56
  • 2
    @Phob: I encourage you to click on the tick mark next to this answer, just below the up/down vote buttons. :-) – C. K. Young Apr 24 '11 at 04:27
  • 4
    Fails with 'Wrong type argument: number-or-marker-p, nil' for me. – Sam Brightman Oct 28 '12 at 12:05
  • 2
    @Micha90 if it shows 0 seconds, it may mean that you need to define the correct .el file to run the profiler on. By default it is `~/.emacs`, but in my case I needed to change it to `~/.emacs.d/init.el`. In the file `profile-dotemacs.el` change the value of the variable named `profile-dotemacs-file`. – rottweiler Jul 11 '16 at 20:12
8

Another solution is ESUP, the Emacs Start Up Profiler. It can profile your config file without leaving Emacs - it accomplishes this by starting a new Emacs as a child process, getting profile information from it.

legoscia
  • 39,593
  • 22
  • 116
  • 167
2

By using divide and conquer, of course!

Drop the bottom half of your .emacs. See if the speed improves. (If so, the culprit is within the bottom half; otherwise it's in the top half.) Restore the working half. Chop off half of the broken half, and repeat the process until you have isolated the problem.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • 1
    This takes O(startup_time * log(config_size)). Startup time = 30 seconds, config_size = 20,000 lines. This works for most people, but is really inconvenient for me. – Phob Apr 24 '11 at 03:03
  • 2
    @Phob: Yeah, 20k lines is seriously more over-the-top than I thought ever possible. ;-) – C. K. Young Apr 24 '11 at 03:07
  • 3
    @Phob, no offense, but 20,000 lines means you're doing it wrong. – Trey Jackson Apr 24 '11 at 04:40
  • 1
    My config is DRY. I am just doing it _more_ . – Phob Aug 11 '11 at 00:19
  • 1
    That's fine if there's one thing that is causing a big slowdown. But it won't work if there are many things culminating in an overall slowdown. – asmeurer May 13 '13 at 00:02