Emacs: Byte Compile Elisp Files

By Xah Lee. Date: . Last updated: .

What is Byte Compiled File

Emacs lisp files can be byte compiled.

emacs byte compiled file 2023-08-23 4kfT
emacs byte compiled file 2023-08-23 4kfT

Advantage of Byte Compiled Elisp File

emacs byte compile 2020-10-14 pCcgM
warnins and tips from byte compile elisp 2020-10-14

As of today (2023-08-23), for init files and light-weight packages, byte compile don't make any noticeable speed difference.

How to Byte Compile Emacs Lisp File

There are several ways to byte compile elisp files. The simplest and most useful are:

Alt+x byte-compile-file
Compile a single file. It'll ask for a file name.
Alt+x dired-do-byte-compileB
Compile all marked files in dired.
Alt+x byte-recompile-directory
Batch compile all elisp files in current dir and subdirectory.

Loading Byte Compiled File

When emacs loads emacs lisp files, normally it will load the byte compiled version if exist. Typically by looking for the file name with the .elc suffix.

The most fundamental loading file mechanism in emacs is the function load.

Your init file, if you are using load, do not add the file name extension such as .el or .elc. This way, emacs will automatically load the byte compiled version when exist.

;; load elisp file, use byte compiled version (.elc) if exist
(load "my_emacs_keybinding")
;; no file name extension here

[see Elisp: load, load-file, autoload]

Recompile When Upgrade

you should recompile your elisp files when:

because often, emacs has some incompatible elisp changes, and big packages may fail without recompile.


2011-07-15 thanks to Adolfo Benedetti https://twitter.com/adben .

Emacs, Byte Compile