Welcome to Applerworld

I like tech and interesting topics

Better performance with Emacs native compile

2021-04-29 2 min read emacs linux guides Sebastian Appler

I recently stumbled upon Emacs native compilation. As native sounds like good I had to try it out. If you also want to try it here’s a quick guide how to compile natively.

We can find some hints on emacswiki but lets walk through it in detail on an Ubuntu system.

First if you compiled Emacs by source before make sure to uninstall it. This can be made with the `make uninstall` command. Don’t worry this will not remove any emacs settings.

cd /your/prevoious/src/emacs
make uninstall

Checkout the source code for native comp:

git clone git://git.savannah.gnu.org/emacs.git emacs-native-comp

On the emacswiki they mention that we need `libgccjit`. That can be installed with this:

sudo apt install libgccjit-10-dev

Ok, we are almost done for some serious compiling. But first we need to set the gcc version. If I skipped this step I would get an error when doing the Emacs configuration.

export CC="gcc-10"

Lets install Emacs:

# Generate configure

# Configuring, this will fail if you dont set the CC variable in the previous step
./configure --with-native-compilation

# Serious compiling...
sudo make -j$(nproc)

# Finially to install emacs native compilation on the system
sudo make install

# Or just run this to try the compilation

If everything went well you should now have a native compiled emacs!

I did some performance tests by starting doom emacs and noting the startup time in shown in the right corner.

Here is the test before and after native comp with my doom emacs setup:

Emacs 27.1 startup time (normal)

~ 0.895s

Emacs native comp startup time


~ 0.746s

Total ~20% faster

As you can see I got around 20% performance boost on startup 8-)