GccEmacs

GccEmacs refers to the feature/native-comp branch of Emacs, which adds support for compiling EmacsLisp to native code using libgccjit. All of the Elisp packages shipped with Emacs are native-compiled, providing a noticeable performance improvement out-of-the-box. Third-party packages may also be compiled to achieve further performance improvements.

The official development log can be found on the gccemacs page.

The feature is discussed in detail in the talk "Bringing GNU Emacs to native code".

Installation

ArchLinux

An emacs-native-comp-git package is available on the AUR.

Install it with your favourite AUR helper, or use the following commands to do it yourself:

    $ git clone https://aur.archlinux.org/emacs-native-comp-git.git
    $ cd emacs-native-comp-git
    $ makepkg --syncdeps --install

Guix

An emacs-native-comp package is available in this channel.

Add the channel to your ~/.config/guix/channels.scm, or use the following commands to install it as a one-off:

    $ git clone https://github.com/flatwhatson/guix-channel.git
    $ guix install --load-path=./guix-channel emacs-native-comp

Nix

An emacsGcc package is available from the Nix community’s Emacs overlay.

Detailed installation instructions are available in this Gist.

Manual

To build the native-comp branch of Emacs, you will need libgccjit in addition to the other dependencies described in BuildingEmacs.

First, checkout the feature/native-comp branch of Emacs, and configure it with the --with-nativecomp flag:

    $ git clone git://git.savannah.gnu.org/emacs.git
    $ cd emacs
    $ git checkout feature/native-comp
    $ ./autogen.sh
    $ ./configure --with-nativecomp

You should see "Does Emacs have native lisp compiler? yes" near the end of the configure output if native compilation has been enabled.

Complete the build with make and make install as usual.

Usage

By default, only the Elisp code which ships with Emacs is native-compiled. To native-compile your third-party packages, a few different approaches are available.

Deferred compilation

Deferred compilation refers to "just-in-time" native compilation of Elisp. When a byte-compiled Elisp module is loaded, it gets queued for native compilation. Once native compilation has finished, the native-compiled definitions automatically replace the byte-compiled versions.

This is simple to use, but may be frustrating if native compilation kicks unexpectedly or at an inconvenient time. You may prefer an "ahead-of-time" solution described further below.

To enable deferred compilation, add the following to your Emacs config:

    ;; enable just-in-time native compilation
    (setq comp-deferred-compilation t)

Ahead-of-time compilation

The simplest solution for "ahead-of-time" compilation is to use a package manager which supports it:

Otherwise, you’ll need to manually native-compile your packages:

    ;; native-compile all Elisp files under a directory
    (native-compile-async "/path/to/packages" 'recursively)

This will add all Elisp files under that directory to the queue for asynchronous native compilation.

If you’re running native compilation from a script, you’ll need to block the Emacs process until the async jobs have completed:

    ;; block until native compilation has finished
    (while (or comp-files-queue
               (> (comp-async-runnings) 0))
      (sleep-for 1))