Faster Emacs Startup with early-init.el
Optimize Emacs startup by eliminating unnecessary visual elements and reducing garbage collection overhead with early-init.el
.
The Problem: Clean and Fast Startup
If you’ve used Emacs for a while, you might be tired of seeing that GNU splash screen every time you open it. It’s like having a roommate who tells you the same joke every morning - it was funny the first time, but now it’s just annoying.
The default Emacs startup process has several issues:
- The startup screen shows unnecessary information.
- GUI elements like the menu bar, tool bar, and scroll bar take up valuable screen space.
- Default frame settings create inconsistent window appearance.
- Default garbage collection settings slow down the startup process.
The Solution: early-init.el
The early-init.el
, a special file to configure Emacs startup, was introduced in Emacs 27.1
It’s like “fastpass” access to configure Emacs before the main initialization process begins.
This is where we can make changes that need to take effect before the UI elements are drawn.
Configuration
I added the following configuration as early-init.el
:
;;; early-init.el --- load before init.el
(custom-set-variables
;; Disable startup screen
'(inhibit-startup-screen t)
'(inhibit-startup-message t)
'(inhibit-startup-echo-area-message t)
'(initial-scratch-message nil)
;; Frame settings
'(initial-frame-alist '((left-fringe . 0)
(right-fringe . 0)
(internal-border-width . 8)
(tool-bar-lines . 0)))
;; Disable UI elements
'(menu-bar-mode nil)
'(scroll-bar-mode nil)
'(tool-bar-mode nil)
;; Buffer settings
'(initial-buffer-choice t)
'(initial-major-mode 'fundamental-mode)
;; Frame behavior
'(frame-inhibit-implied-resize t)
'(frame-title-format nil)
'(cursor-in-non-selected-windows nil)
;; Font settings
'(font-lock-maximum-decoration nil)
'(font-lock-maximum-size nil)
'(x-underline-at-descent-line t)
;; Window divider settings
'(window-divider-default-right-width 16)
'(window-divider-default-places 'right-only)
;; Performance settings
'(gc-cons-threshold most-positive-fixnum))
;; For Emacs v29
(add-to-list 'default-frame-alist '(undecorated . t))
(provide 'early-init)
;;; early-init.el ends here
My Emacs screen is now stripped down to its bare essentials, with every pixel serving a purpose!
Memory Management for Performance
Emacs performance optimization requires balancing two key aspects:
- Startup speed
- Runtime responsiveness
Our configuration achieves this through two-phase garbage collection.
Phase 1: Fast Startup
I added the following configuration at early-init.el
and at the top of init.el
:
(setq gc-cons-threshold most-positive-fixnum)
Phase 2: Smooth Runtime
I added the following configuration at the end of init.el
:
(setq gc-cons-threshold 16777216) ; 16MB
The profiler reported that the startup time was improved by 5% 👍
Wrap Up
With this early-init.el
configuration, your Emacs starts faster and cleaner.
Just place it in your .emacs.d/
directory alongside init.el
, and you’re good to go.
The state of init.el
at the conclusion of this article can be found here 🚀
comments powered by Disqus