Faster Alacritty start-ups with single-instance mode

2 min read

I've been using URxvt for almost a decade, mainly because its client/server (or daemon) mode makes spawning new terminal windows extremely fast and lightweight. Unfortunately, it is showing its age, and unless you apply a few patches that have been floating around for quite some time, you will likely encounter the following issues:

  • Lack of true color support.
  • Invalid glyph spacing.
  • Buggy rendering of wide Unicode glyphs (necessary for icon fonts).

In search of a modern terminal emulator, I tried a few options:

  • VTE-based ones like Termite, but they are too slow, they take too much resources, and they lack features like adjusting the glyph spacing.
  • Foot, but it only runs under Wayland.
  • Kitty, but it has weird limitations like missing support for sub-pixel rendering which makes the fonts ugly on standard displays.

Finally, I settled on Alacritty. It has most of the features I care about:

  • Proper Unicode font rendering with glyph width/height adjustment.
  • Batteries included (URL copying, scrollback buffer, customizable keybindings).
  • And of course, it is written in Rust.

Like Kitty, Alacritty relies on GPU rendering. I can't say that I feel all of the benefits compared to URxvt, but one thing I can feel is that opening a new terminal window is noticeably slower, because creating a GPU rendering context is not fast. That brings us to the subject of this article.

Alacritty supports sending an IPC message to create a new window that shares all the rendering context with an existing instance, which is faster and lighter than creating a new instance:

New CPU Memory Command
Instance 175ms 89 MB alacritty --socket /tmp/test.sock
Window 6ms 7 MB alacritty msg create-window

In a single command, you can try to create a new window, or fallback to creating the instance if it doesn't exist yet:

$ alacritty msg --socket "$XDG_RUNTIME_DIR/alacritty.sock" create-window \
    || alacritty --socket "$XDG_RUNTIME_DIR/alacritty.sock"

The only drawback is that if a window crashes for some reason (which should be an exceptional situation), it will bring down all the other windows that are part of this instance.