As I add more and more plugins and configurations to my emacs' init.el , it's startup is getting more and more slow. Is there any way to avoid this?
-
2possible duplicate of [How can I make Emacs start-up faster?](http://stackoverflow.com/questions/778716/how-can-i-make-emacs-start-up-faster) – Trey Jackson Apr 16 '11 at 14:31
2 Answers
Your .emacs
or init.el
shouldn't have many require
or load
commands, it should mostly have autoload
. The autoload
function tells Emacs “if you ever need this function, load that file”. This way, the file is only loaded when and if you actually use the function. You only need require
(or very rarely load
) in two cases:
- if there's a customization that needs to go into effect immediately (e.g.
(require 'cl)
, a color theme); - if what you're loading is a small file that contains the
autoloads
and other start-up definitions of a package (e.g.(require 'tex-site)
.
If you're not doing this already, calling autoload
for things like mode-specific customizations can cut your startup time down significantly, because Emacs will have to load fewer files.
Furthermore, make sure your files are byte-compiled; they'll load a little faster (less CPU time). Call M-x emacs-lisp-byte-compile
on each .el
file, or M-x byte-recompile-directory
(these commands are in the Emacs-Lisp menu).
Finally, note that load times don't matter so much because you should be starting Emacs at most once per session. Start Emacs automatically when you log in, either with a window or in the background with the --daemon
option. Then, to edit a file, run emacsclient
. You can also tell emacsclient
to start Emacs if it's not running yet if you'd rather not start it when you log in.

- 104,111
- 38
- 209
- 254
-
1For people having problems with the daemon mode and the editor colors, this is very useful: http://www.emacswiki.org/emacs/SettingFrameColorsForEmacsClient – dermatthias Apr 16 '11 at 21:28
-
If you don't like confirming every directory and/or file: `(byte-recompile-directory "~/where-i-put-my-packages/" nil nil)` or change the last nil value to something non-nil to force recompilation. `(describe-function 'byte-recompile-directory)` rocks :) – clintm Nov 24 '11 at 08:08
You can compile it as an .elc file (M-x byte-compile-file)

- 33,372
- 17
- 89
- 105
-
From [48.4 The Emacs Initialization File](http://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html#Init-File): *"Byte-compiling your init file is not recommended ... If your init file defines many functions, consider moving them to a separate (byte-compiled) file that you load in your init file."* – DavidRR Jul 15 '15 at 15:47
-
...That said, there are suggested mechanisms for automatically maintaining a byte-compiled version of your Emacs initialization file. For instance, see [here](http://stackoverflow.com/a/779145/1497596) and [here](http://stackoverflow.com/a/780735/1497596). – DavidRR Jul 15 '15 at 16:08