Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make my customized emacs load faster?

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?

like image 795
Pedro Rolo Avatar asked Apr 15 '11 20:04

Pedro Rolo


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.

like image 71
Gilles 'SO- stop being evil' Avatar answered Oct 03 '22 08:10

Gilles 'SO- stop being evil'


You can compile it as an .elc file (M-x byte-compile-file)

like image 23
Joel Spolsky Avatar answered Oct 03 '22 10:10

Joel Spolsky