The compile-angel Emacs package automatically byte-compiles and native-compiles Emacs Lisp libraries. It offers:
(compile-angel-on-load-mode)
: A global mode that compiles .el files before they are loaded.(compile-angel-on-save-local-mode)
: A local mode that compiles .el files whenever the user saves them.
The compile-angel modes speed up Emacs by ensuring all libraries are byte-compiled and native-compiled. Byte-compilation reduces the overhead of loading Emacs Lisp code at runtime, while native compilation optimizes performance by generating machine code specific to your system.
Why use compile-angel?
Because you are likely running a significant amount of interpreted, slow Elisp code. Ensuring that Elisp is native-compiled significantly improves Emacs’ performance. This is because functions like package-install and package-recompile-all do not compile .el files in the load-path paths that were not installed using package.el. Since these files are not byte-compiled, the Emacs JIT compiler does not native-compile them either, as a byte-compiled file signals the JIT compiler to perform native compilation. In contrast, compile-angel modes ensure that all loaded .el files are compiled transparently, regardless of whether they are part of a package.
Install compile-angel from MELPA
- If you haven’t already done so, add MELPA repository to your Emacs configuration.
- Add the following code at the very beginning of your Emacs init file, before all other packages:
(use-package compile-angel
:ensure t
:demand t
:custom
(compile-angel-verbose nil)
:config
(compile-angel-on-load-mode)
(add-hook 'emacs-lisp-mode-hook
#'compile-angel-on-save-local-mode))
Code language: Lisp (lisp)
Links
- Read more about how to customize the compile-angel package: compile-angel.el @GitHub.
- For those who prefer compiling .el files from the command line: elispcomp
- Article on irreal.org: Compile Angel
- Reddit r/emacs: Compile-angel.el: Automatically Byte-compile and native-compile Emacs Lisp libraries