![[Home]](https://www.emacswiki.org/images/logo218x38.png)
GccEmacs refers to the --with-native-compilation configuration option when building 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 are also 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 paper "Bringing GNU Emacs to native code" and related talk.
To build GccEmacs, you will need libgccjit in addition to the other dependencies described in BuildingEmacs.
First, checkout the latest stable release branch (from emacs-28 onwards) or the unstable master branch, and configure it with the --with-native-compilation flag:
$ git clone git://git.savannah.gnu.org/emacs.git
$ cd emacs
$ git checkout emacs-28
$ ./autogen.sh
$ ./configure --with-native-compilation
$ make -j$(nproc)You should see "Does Emacs have native lisp compiler? yes" near the end of the configure output if native compilation has been enabled.
If you wish, install conventionally with make install otherwise run it from the build tree with ./src/emacs.
If you’re using unixy system with non-root access and would like to install emacs from source without being bothered by installing dependencies. At the time of writing, this only supports native compilation with the unstable master branch.
$ git clone https://github.com/spack/spack.git
$ ./spack/bin/spack install emacs@master+native+tlsif spack doesn’t work, set SPACK_PYTHON to python3 path. You can customize more, see https://github.com/spack/spack/blob/develop/var/spack/repos/builtin/packages/emacs/package.py for options.
dnf copr enable deathwish/emacs-pgtk-nativecomp
then
dnf update emacs
or
dnf install emacs
The openSUSE Tumbleweed emacs-* packages are officially built with the option.
An emacs-nativecomp package is available in the official extra repository, which is enabled by default.
pacman -S emacs-nativecomp
The emacs-snapshot packages are now built with this support: http://emacs.secretsauce.net
If systemctl --user start emacs.service immediately crashes and journalctl --user -u emacs mentions a long path mentioning native-lisp and ending with .eln, add the following line to the [Service] section in /usr/lib/systemd/user/emacs.service:
WorkingDirectory=/usr/lib/emacs/28.0.50/x86_64-pc-linux-gnu/
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-compAn emacsGcc package is available from the Nix community’s Emacs overlay.
Detailed installation instructions are available in this Gist.
An emacs-nativecomp docker image is available. Also examine the gitlab repo for the dockerfile.
The Gccemacs prebuilt packages are available and updated daily using GitHub action. The build script is also available.
$ brew tap jimeh/emacs-builds
$ brew install --cask emacs-app-nightly-28It’s also possible to install the package via homebrew with this formula.
$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus@28 --with-native-compThe Gccemacs prebuilt packages are available and updated semi-monthly using GitHub action. The build script is also available in the same github repo.
It’s also possible to install the package via scoop with this bucket.
$ scoop bucket add kiennq-scoop https://github.com/kiennq/scoop-misc
$ scoop install emacs-k
By default Emacs ships only native compiling the files included in the Emacs image.
The native compilation of the remaining Emacs distribution and external packages happen automatically and asynchronously (See 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 as it does not require any user intervention. You may prefer an "ahead-of-time" solution described further below.
Deferred compilation is enabled by default and controlled by the comp-deferred-compilation customize.
Sometimes it is useful to compile ahead-of-time, for example if you are packaging Emacs for others.
It is possible to native compile ahead-of-time all the Emacs distribution using the NATIVE_FULL_AOT, for example:
$ make NATIVE_FULL_AOT=1 -j$(nproc)
The built-in package manager package.el supports ahead-of-time native compilation when installing a package. Customize the user option ‘package-native-compile’ or add this to your init file to enable it:
(setq package-native-compile t)
Some third-party package managers also support ahead-of-time native compilation:
You can native-compile your packages manually:
;; native-compile all Elisp files under a directory (native-compile-async "/path/to/packages" 'recursively)
This will add all Emacs Lisp files under that directory to the queue for asynchronous native compilation.
If you are running native compilation from a script, you will 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))
If you’re running anti-virus software, each native-compiled library may get scanned for viruses when loaded, which can have a dramatic impact on loading performance, especially when starting Emacs for the first time in a session.
If you’re experiencing such slowness, test disabling your anti-virus to see whether that’s the cause.