Native Compilation in Emacs

Andrea Corallo gave an interesting talk at EmacsConf 2021 on his Emacs Lisp native compilation project. For those who don’t know, the native compilation project provides a compiler that converts Emacs Lisp into native code for the host machine. The idea is to enable the elimination of much of the Emacs C code in favor of Elisp. Native compilation will be officially released with Emacs 28, which is currently at the Pretest 1 phase. That means that native compilation will soon be available and supported for anyone who wants it.

Corallo’s implementation is a tour de force. His idea was to convert the Elisp byte code into IR for the GCC. He started off with a straightforward translation from the byte code to IR but the Elisp virtual machine is stack based whereas modern CPUs are register based. That means that the naive approach didn’t realize the performance increase you’d expect.

The current implementation has several passes to translate and optimize Elisp byte code into GCC IR code that GCC can also optimize and use to generate efficient machine code. Corallo’s talk takes us through the compilation process and explains the problems he encountered.

I found that it was easier to view the video on Toobnix because I could make it full screen. The video itself is 39 minutes 8 seconds long so you will need to set some time aside. If you have any interest in this technology, the video is definitely worth your time. Even if you don’t care about the technical details, native compilation is going to be a boon to your Emacs experience simply because things will be faster.

This entry was posted in General and tagged . Bookmark the permalink.