17

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

Phob
  • 841
  • 8
  • 12

3 Answers3

31

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
  • 17,806
  • 3
  • 40
  • 57
  • 2
    The wiki is a source of infinite wisdom for all things Emacs. – Noufal Ibrahim Apr 23 '11 at 05:56
  • This is awesome!! Exactly what I was looking for. – Phob Apr 24 '11 at 03:02
  • 2
    @Phob: I encourage you to click on the tick mark next to this answer, just below the up/down vote buttons. :-) – Chris Jester-Young Apr 24 '11 at 04:27
  • 3
    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
7

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
  • 38,687
  • 22
  • 110
  • 157
  • 1
    I installed esup, did M-x esup... and that's it. IDK how it was in 2016, but in 2020 `esup`was really simple to use to me. – YoungFrog Jul 28 '20 at 07:25
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.

Chris Jester-Young
  • 213,251
  • 44
  • 377
  • 423