Add optimizations, auto-compile, and gcmh
This commit is contained in:
@@ -14,30 +14,77 @@
|
||||
|
||||
;;; Code:
|
||||
|
||||
;;; Load pre-early-init.el
|
||||
(defvar minimal-emacs--default-user-emacs-directory user-emacs-directory
|
||||
"The default value of the `user-emacs-directory' variable.")
|
||||
(defun minimal-emacs-load-user-init (filename)
|
||||
"Execute a file of Lisp code named FILENAME."
|
||||
(let ((user-init-file (expand-file-name filename
|
||||
user-emacs-directory)))
|
||||
(let ((user-init-file
|
||||
(expand-file-name filename
|
||||
minimal-emacs--default-user-emacs-directory)))
|
||||
(when (file-exists-p user-init-file)
|
||||
(load user-init-file))))
|
||||
|
||||
(minimal-emacs-load-user-init "pre-early-init.el")
|
||||
|
||||
;;; Variables
|
||||
|
||||
(defvar minimal-emacs-gc-cons-threshold (* 16 1024 1024)
|
||||
"The value of `gc-cons-threshold' after Emacs startup.")
|
||||
|
||||
;;; Garbage collection
|
||||
;; Garbage collection significantly affects startup times. This setting delays
|
||||
;; garbage collection during startup but will be reset later.
|
||||
(defvar minimal-emacs-default-gc-cons-threshold gc-cons-threshold
|
||||
"The default value of `gc-cons-threshold'.")
|
||||
(setq gc-cons-threshold most-positive-fixnum)
|
||||
(add-hook 'emacs-startup-hook (lambda ()
|
||||
(setq gc-cons-threshold (* 16 1024 1024))))
|
||||
|
||||
;; Prefer loading newer compiled files
|
||||
(setq load-prefer-newer t)
|
||||
;;; file-name-handler-alist
|
||||
|
||||
;; During startup, Emacs will process every opened and loaded file through this
|
||||
;; list to identify a suitable handler. However, at that point, it won't
|
||||
;; require any of them.
|
||||
(defvar minimal-emacs--default-file-name-handler-alist file-name-handler-alist
|
||||
"The default value of the `file-name-handler-alist' variable.")
|
||||
(setq file-name-handler-alist nil)
|
||||
(defun minimal-emacs--restore-file-name-handler-alist ()
|
||||
"Restore the variables that were modified by `early-init.el'."
|
||||
(setq file-name-handler-alist minimal-emacs--default-file-name-handler-alist))
|
||||
(add-hook 'emacs-startup-hook #'minimal-emacs--restore-file-name-handler-alist)
|
||||
|
||||
;; Byte comp
|
||||
(setq load-prefer-newer t) ; Prefer loading newer compiled files
|
||||
|
||||
;; Native comp
|
||||
(defvar minimal-emacs-native-comp-reserved-cpus 2
|
||||
"Number of CPUs to reserve and not use for `native-compile'.")
|
||||
|
||||
(defun minimal-emacs-calculate-native-comp-async-jobs ()
|
||||
"Set `native-comp-async-jobs-number' based on the available CPUs."
|
||||
;; The `num-processors' function is only available in Emacs >= 28.1
|
||||
(max 1 (- (num-processors) minimal-emacs-native-comp-reserved-cpus)))
|
||||
|
||||
(if (and (featurep 'native-compile)
|
||||
(fboundp 'native-comp-available-p)
|
||||
(native-comp-available-p))
|
||||
;; Activate `native-compile'
|
||||
(setq native-comp-async-jobs-number
|
||||
(minimal-emacs-calculate-native-comp-async-jobs)
|
||||
native-comp-deferred-compilation t
|
||||
package-native-compile t)
|
||||
;; Deactivate the `native-compile' feature if it is not available
|
||||
(setq features (delq 'native-compile features)))
|
||||
|
||||
;;; Simple UI
|
||||
|
||||
;; Disable startup screens and messages
|
||||
(setq inhibit-startup-screen t)
|
||||
(setq initial-scratch-message nil)
|
||||
(setq inhibit-splash-screen t)
|
||||
|
||||
;; Disable unneeded UI elements
|
||||
;;; Disable unneeded UI elements
|
||||
(when (fboundp 'tooltip-mode)
|
||||
(tooltip-mode -1))
|
||||
(unless (memq window-system '(mac ns))
|
||||
@@ -49,6 +96,42 @@
|
||||
(when (fboundp 'horizontal-scroll-bar-mode)
|
||||
(horizontal-scroll-bar-mode -1))
|
||||
|
||||
;;; package: Set package archives for package installation
|
||||
(progn
|
||||
(require 'package)
|
||||
(setq package-enable-at-startup nil)
|
||||
(setq package-quickstart nil)
|
||||
|
||||
(when (version< emacs-version "28")
|
||||
(add-to-list 'package-archives
|
||||
'("nongnu" . "https://elpa.nongnu.org/nongnu/")))
|
||||
(add-to-list 'package-archives
|
||||
'("stable" . "https://stable.melpa.org/packages/"))
|
||||
(add-to-list 'package-archives
|
||||
'("melpa" . "https://melpa.org/packages/"))
|
||||
|
||||
(customize-set-variable 'package-archive-priorities
|
||||
'(("gnu" . 99)
|
||||
("nongnu" . 80)
|
||||
("stable" . 70)
|
||||
("melpa" . 0)))
|
||||
(when package-enable-at-startup
|
||||
(package-initialize)))
|
||||
|
||||
;;; use-package:
|
||||
(progn
|
||||
;; Always ensure packages are installed
|
||||
(setq use-package-always-ensure t)
|
||||
|
||||
;; Ensure the 'use-package' package is installed
|
||||
(unless (package-installed-p 'use-package)
|
||||
(package-install 'use-package))
|
||||
|
||||
;; Load use-package for package configuration
|
||||
(eval-when-compile
|
||||
(require 'use-package)))
|
||||
|
||||
;;; Load post-early-init.el
|
||||
(minimal-emacs-load-user-init "post-early-init.el")
|
||||
|
||||
(provide 'early-init)
|
||||
|
||||
40
init.el
40
init.el
@@ -17,40 +17,14 @@
|
||||
;;; Load user-pre-init.el
|
||||
(minimal-emacs-load-user-init "pre-init.el")
|
||||
|
||||
;;; package: Set package archives for package installation
|
||||
(progn
|
||||
(require 'package)
|
||||
(setq package-enable-at-startup nil)
|
||||
(setq package-quickstart nil)
|
||||
(use-package auto-compile
|
||||
:config
|
||||
(auto-compile-on-load-mode)
|
||||
(auto-compile-on-save-mode))
|
||||
|
||||
(when (version< emacs-version "28")
|
||||
(add-to-list 'package-archives
|
||||
'("nongnu" . "https://elpa.nongnu.org/nongnu/")))
|
||||
(add-to-list 'package-archives
|
||||
'("stable" . "https://stable.melpa.org/packages/"))
|
||||
(add-to-list 'package-archives
|
||||
'("melpa" . "https://melpa.org/packages/"))
|
||||
|
||||
(customize-set-variable 'package-archive-priorities
|
||||
'(("gnu" . 99)
|
||||
("nongnu" . 80)
|
||||
("stable" . 70)
|
||||
("melpa" . 0)))
|
||||
(when package-enable-at-startup
|
||||
(package-initialize)))
|
||||
|
||||
;;; use-package:
|
||||
(progn
|
||||
;; Always ensure packages are installed
|
||||
(setq use-package-always-ensure t)
|
||||
|
||||
;; Ensure the 'use-package' package is installed
|
||||
(unless (package-installed-p 'use-package)
|
||||
(package-install 'use-package))
|
||||
|
||||
;; Load use-package for package configuration
|
||||
(eval-when-compile
|
||||
(require 'use-package)))
|
||||
(use-package gcmh
|
||||
:hook
|
||||
(emacs-startup . gcmh-mode))
|
||||
|
||||
;;; Load user-pre-init.el
|
||||
(minimal-emacs-load-user-init "post-init.el")
|
||||
|
||||
Reference in New Issue
Block a user