The compile-angel Emacs package: Byte-compile and Native-compile Emacs Lisp libraries Automatically

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

  1. If you haven’t already done so, add MELPA repository to your Emacs configuration.
  2. 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

Leave a Reply

Your email address will not be published. Required fields are marked *