Make Emacs Faster
💡 This guide is outdated. There exists an AUR package called
emacs-nativecomp
which you can install to achieve the same result.
Emacs is probably my favourite "text editor" to use on Linux, as it is so extensible. However, the one thing that puts many people off using it (ignoring its complexity), is the fact that it is only single threaded, and can at times feel a little sluggish when compared to other editors like Vim.
With Emacs 28.1, along with the libgccjit (Just-In-Time Compilation with GCC) library, we now have the ability to translate Emacs Lisp into machine code on demand - which will speed things up. With this, you may notice a drastic speed increase during your day-to-day use of Emacs.
💡 For this guide I'm using an Arch-based Linux distribution called EndeavourOS, and the DOOM Emacs config.
Uninstall Emacs
If you've already installed an older version of Emacs with your package manager - uninstall it:
1yay -R emacs
Download Emacs
First we need to download the source code for the latest version of Emacs. For this example we'll be using Emacs 28.2, but the same steps will apply for later versions.
1cd
2wget https://ftp.gnu.org/gnu/emacs/emacs-28.2.tar.xz
Unpack
Then we need to unpack it:
1tar -xf emacs-28.2.tar.xz
Let's navigate into the Emacs source folder:
1cd emacs-28.2/
Install libgccjit
Now let's install the required JIT compilation with GCC backend library:
1yay -S libgccjit
Building
We can now build Emacs:
1./configure --with-native-compilation
Now, we can make:
1make -j$(nproc)
And lastly, install it for use:
1sudo make install
2
3# where is it?
4whereis emacs
5# > emacs: /usr/local/bin/emacs /usr/local/lib/emacs /usr/share/emacs
6
7# check version
8emacs --version
9# > emacsclient 28.2
DOOM Emacs Users
Once you've compiled and installed Emacs with native compilation, ensure you run the following command to compile your Emacs packages:
1doom sync
Emacs Client
I like to run the emacsclient rather than launching a single instance of Emacs when needed. By doing this I can launch into it faster, as the emacsclient runs continually in the background and will spawn new windows almost instantly.
In your application startup add this:
1emacs --daemon &
If you use a window manager, you may wish to add a command to launch emacsclient in your autorun script, like I do, as shown here using awesomeWM.
In your hotkeys, you can add a command to launch Emacs in client mode. This is how I do it using sxhkd:
1# ~/config/sxhkd/sxhkdrc
2
3# Emacs
4super + alt + m
5 emacsclient -c -a emacs
Set Emacs As Default Editor
You can make Emacs your default text editor by setting up a few variables which your system will use when you log in. To do this, edit your .profile
file in your $HOME
and add the following:
1# ~/.profile
2export EDITOR="emacsclient -t"
3export CODEEDITOR="emacsclient -c -a 'emacs'"
4export VISUAL="emacsclient -c -a 'emacs'"
5export SUDO_EDITOR="emacsclient -t"