My emacs configuration takes a very long time to load. How can I easily find the offending parts and optimize them?
Asked
Active
Viewed 6,809 times
20
-
How long is "very long" ? I never imagined emacs being something that would take long to load. – Mike Bailey Apr 23 '11 at 04:19
-
30 seconds, even with Raid 0 SSDs :-( :-( – Phob Apr 24 '11 at 02:55
-
1Be sure to look at http://stackoverflow.com/questions/778716/how-can-i-make-emacs-start-up-faster to see how to fix the problem. – Trey Jackson Apr 24 '11 at 04:38
-
@Trey, thanks. I already do everything there but autoloads, which seem tedious. – Phob May 23 '11 at 04:09
3 Answers
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
-
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
-
4Fails 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
-
1I 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.

C. K. Young
- 219,335
- 46
- 382
- 435
-
1This 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
-
1
-
1That'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