Install and use Emacs 28 Native comp (gccemacs)
Features
GCC Emacs uses libgccjit to compile and run Emacs Lisp as native code in form of re-loadable elf files. Therefore, it reaches a 3.8 times faster performance.
More details can be found in the paper.
Installation
MacOS
First enable gcc with libgccjit. cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula
and edit gcc.rb
|
|
Then run brew install gcc
.
After successful installation of libgccjit, there are (at least) four ways to compile Emacs native comp (emacs-plus@28 works for my laptop with Big Sur 11.4).
- https://github.com/d12frosted/homebrew-emacs-plus.git
- https://github.com/daviderestivo/homebrew-emacs-head
- https://github.com/jimeh/build-emacs-for-macos.git
- https://github.com/jimeh/homebrew-emacs-builds.git (binary)
After compilation, it takes a while to compile your lisp codes. Just wait.
Windows
Enable WSL2 and install ArchWSL
To enable WSL2 in Windows, follow the steps in microsoft doc. You can also download kernel update package if you have already installed it.
Since Arch Linux is not included in the Microsoft Store, we need to install it manually. However, yuk7 has a project to make this possible and easy to do based on a perfect documentation.
|
|
Install yay (an AUR helper)
|
|
Add gpg key of libgccjit
This step is needed because libgccjit key is not included in archwsl. Use the command below to add it.
|
|
Install Emacs 28 (each one should work)
|
|
Use XServer to run GUI app
After installation, you can run Emacs but it won’t show xwindow as you expect. You need use a XServer (e.g., MobaXterm, X410, VcXsrv) to do this. Several months ago I’ve written a post that describes my experience of using Emacs on Windows, check it if you like.
It’s also worth noting that in the next generation of Windows, an official GUI support, WSLG
, will be provided by Microsoft. You may want to check it.
|
|
Linux (Ubuntu)
If you don’t want to build from source or are not able to do this due to lack of full permission, you might need the following two ways.
Emacs-ng
Emacs-ng is based off of the branch of emacs, and regularly merges in the latest changes(this branch includes the native compilation feature from Andrea Corallo).
One can easily download package file (.deb) from release page and use sudo dpkg -i xxx.deb
to install it.
Note Emacs-ng includes many experimental features powered by webrender and Google V8 engine, which means it’s a fork instead of a Vanilla Emacs.
Snap
Emacs-snap is another way to install latest Emacs in Ubuntu. It’s maintained by Alex Murray and now it includes native-comp.
Emacs configurations
Clone straight.el (optional)
The original boostrap code of straight.el won’t work in WSL2, so we need clone the repository to the .emacs.d
directory. See the Debugging section of doc.
|
|
Native comp support
Download your configuration file with codes below to unleash its power.
|
|
Conclusion
My experience is that it’s significantly faster on Mac, which is why I spend more time cloning this on Windows. However, on WSL2 I really can’t find the difference because the Emacs 28 without native comp feature on WSL2 is already very fast (init time < 1.0s). Given the blurry problem of running GUI app based on XServer on a high DPI screen, consider twice before your decision.