diff options
Diffstat (limited to 'early-init.el')
| -rw-r--r-- | early-init.el | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/early-init.el b/early-init.el index d45faef79..f2ed5bfa3 100644 --- a/early-init.el +++ b/early-init.el @@ -1,36 +1,14 @@ -;;; early-init.el --- -*- lexical-binding: t; coding: utf-8; no-byte-compile: t; -*- +;;; early-init.el --- Startup bootstrap before init.el -*- lexical-binding: t; coding: utf-8; no-byte-compile: t; -*- ;;; Commentary: - -;; DEBUG FLAGS -;; Debug flags are default on while this config is loading since errors should -;; be loud and highly noticeable. They are restored to their default off once -;; the config has completed. - -;; STARTUP PERFORMANCE -;; Increasing garbage collection to a very high number decreases startup time. -;; setting the file-name-handler and vc-handled-backends avoids some regexp -;; slowness during startup. All original values are restored once Emacs is -;; finished with startup. - -;; LOCAL REPOSITORIES -;; This config doesn't work if the packages it relies on fail. Having local -;; package repositories also allows for full config portability behind corporate -;; firewalls and fast recovery from package issues no matter the network -;; situation. - -;; The localrepo directory contains all the last known good packages for this -;; config. The directory is added as a repository to the package archive list -;; first, and given the highest priority number. This allows for a portable -;; installation and reinstallation. This directory averages ~70 MB. - -;; Having a full local mirror of all elpa, melpa, and org repositories gives you -;; more flexibility but at a higher storage cost. The script -;; 'create-elpa-mirror.sh in user-emacs-directory/scripts directory will clone -;; them all locally. As of Saturday, March 30, 2024 the directory containing all -;; gnu, nongnu, melpa, melpa-stable, and org packages takes around 1.9 GB. -;; For more information on the localrepo and elpa mirrors, read the commentary -;; in local-repository.el. +;; +;; Early startup policy: make init errors loud, speed package/bootstrap work, +;; configure package archives, and suppress expensive UI defaults before the +;; first frame appears. +;; +;; Package archives prefer the checked-in localrepo, then local ELPA mirrors, +;; then online archives. Startup-only GC and file-name-handler changes are +;; paired with later session owners such as gcmh. ;;; Code: @@ -43,7 +21,8 @@ ;; (add-hook 'after-init-hook 'benchmark-init/deactivate)) ;; -------------------------------- Debug Flags -------------------------------- -;; debugging enabled during Emacs startup. disabled again after Emacs startup. +;; Keep debug-on-error enabled only during startup; the startup hook restores the +;; normal interactive behavior after init has loaded. ;; uncomment when repo signatures expire and package installation is necessary ;; (setq package-check-signature nil) @@ -60,14 +39,23 @@ (lambda () (setq debug-on-error nil))) -;; ------------------------------ Bug Workarounds ------------------------------ +;; ------------------------------ Native Compilation --------------------------- + +;; Enable JIT native compilation. Packages are natively compiled on first load +;; (asynchronously, in the background) and cached as .eln for later sessions. +;; This was previously disabled via `(setq native-comp-deferred-compilation +;; nil)' -- the obsolete alias of `native-comp-jit-compilation'. Despite the old +;; comment, setting it nil turns JIT OFF entirely (not "synchronous"), so most +;; modules ran interpreted for the daemon's lifetime and the +;; `native-comp-speed'/jobs settings in system-defaults.el were dead. The old +;; "Selecting deleted buffer" async race that prompted the disable was an Emacs +;; 28/29 issue; this is 30.2. +(setq native-comp-jit-compilation t) -;; Disable async native compilation to prevent "Selecting deleted buffer" errors -;; This is a known issue in Emacs 30.x where async compilation buffers get -;; deleted before the compilation process completes. Synchronous compilation -;; is slower initially but avoids these race conditions. -(setq native-comp-deferred-compilation nil) ;; Disable async/deferred compilation -(setq native-comp-async-report-warnings-errors nil) ;; Silence async warnings +;; Log async-compile warnings to the *Async-native-compile-log* buffer rather +;; than popping a window. (system-defaults.el also routes `comp' display-warnings +;; to a file via `cj/log-comp-warning'.) +(setq native-comp-async-report-warnings-errors 'silent) ;; ------------------------------- Load Freshness ------------------------------ ;; Prefer newer .el source over stale .elc byte-compiled files. Without this, @@ -99,11 +87,13 @@ local repos." :group 'cj) ;; ---------------------------- Startup Performance ---------------------------- -;; increases garbage collection threshold and turns off file-name-handler -;; during startup and restores the settings once emacs has loaded. +;; Bump the GC threshold and turn off the file-name-handler during startup for +;; speed. The file-name-handler is restored once Emacs has loaded. The GC +;; threshold is deliberately NOT restored here -- `gcmh' (configured in +;; system-defaults.el) owns `gc-cons-threshold' for the rest of the session, +;; keeping it high during activity and collecting on idle. Restoring the stock +;; 800KB here would fight gcmh and bring back frequent GC pauses. -(defvar cj/orig-gc-cons-threshold gc-cons-threshold - "Temporary variable to allow restoration of value post-startup.") (setq gc-cons-threshold most-positive-fixnum) (defvar cj/orig-file-name-handler-alist file-name-handler-alist @@ -112,8 +102,7 @@ local repos." (add-hook 'emacs-startup-hook (lambda () - (setq gc-cons-threshold cj/orig-gc-cons-threshold - file-name-handler-alist cj/orig-file-name-handler-alist))) + (setq file-name-handler-alist cj/orig-file-name-handler-alist))) ;; ------------------------------ Site Start Files ----------------------------- ;; don't load site-start or default.el files @@ -307,6 +296,8 @@ early-init.el.") bidi-inhibit-bpa t) ;; additional speedup ;; Disable global font lock mode until after initialization +;; Defer global font-lock until init finishes; major modes re-enable normal +;; highlighting after startup. (setq-default global-font-lock-mode nil) (add-hook 'emacs-startup-hook #'global-font-lock-mode) |
