Enhance garbage collection
- Enhance early-init garbage collection optimization (Add support for: gc-cons-percentage) - Make minimal-emacs-load-user-init display messages when init-file-debug is non-nil - Update README.md
This commit is contained in:
@@ -9,7 +9,7 @@ The **minimal-emacs.d** project is a lightweight and optimized Emacs base (`init
|
|||||||
|
|
||||||
Building the *minimal-emacs.d* `init.el` and `early-init.el` was the result of **extensive research and testing** to fine-tune the best parameters and optimizations for an Emacs configuration. *(More information about the *minimal-emacs.d* features can be found here: [Features](#features).)*
|
Building the *minimal-emacs.d* `init.el` and `early-init.el` was the result of **extensive research and testing** to fine-tune the best parameters and optimizations for an Emacs configuration. *(More information about the *minimal-emacs.d* features can be found here: [Features](#features).)*
|
||||||
|
|
||||||
If this enhances your workflow, please show your support by **⭐ starring minimal-emacs.d GitHub** to help more users discover its benefits.
|
If this enhances your workflow, please show your support by **⭐ starring minimal-emacs.d GitHub** to help more Emacs users discover its benefits.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://jamescherti.com/misc/minimal-emacs.d.png" width="50%" />
|
<img src="https://jamescherti.com/misc/minimal-emacs.d.png" width="50%" />
|
||||||
|
|||||||
@@ -24,10 +24,14 @@
|
|||||||
|
|
||||||
;;; Internal variables
|
;;; Internal variables
|
||||||
|
|
||||||
(defvar minimal-emacs--backup-gc-cons-threshold gc-cons-threshold
|
;; Backup of `gc-cons-threshold' and `gc-cons-percentage' before startup.
|
||||||
"Backup of the original value of `gc-cons-threshold' before startup.")
|
(defvar minimal-emacs--backup-gc-cons-threshold gc-cons-threshold)
|
||||||
|
(defvar minimal-emacs--backup-gc-cons-percentage gc-cons-percentage)
|
||||||
|
|
||||||
(setq gc-cons-threshold most-positive-fixnum)
|
;; Temporarily raise the garbage collection threshold to its maximum value.
|
||||||
|
;; It will be restored later to controlled values.
|
||||||
|
(setq gc-cons-threshold (- most-positive-fixnum 1))
|
||||||
|
(setq gc-cons-percentage 1.0)
|
||||||
|
|
||||||
;;; Variables
|
;;; Variables
|
||||||
|
|
||||||
@@ -55,6 +59,10 @@ stored in `minimal-emacs-gc-cons-threshold'.")
|
|||||||
"Value to which `gc-cons-threshold' is set after Emacs startup.
|
"Value to which `gc-cons-threshold' is set after Emacs startup.
|
||||||
Ignored if `minimal-emacs-optimize-startup-gc' is nil.")
|
Ignored if `minimal-emacs-optimize-startup-gc' is nil.")
|
||||||
|
|
||||||
|
(defvar minimal-emacs-gc-cons-percentage gc-cons-percentage
|
||||||
|
"Value to which `gc-cons-percentage' is set after Emacs startup.
|
||||||
|
Ignored if `minimal-emacs-optimize-startup-gc' is nil.")
|
||||||
|
|
||||||
(defvar minimal-emacs-gc-cons-threshold-restore-delay nil
|
(defvar minimal-emacs-gc-cons-threshold-restore-delay nil
|
||||||
"Number of seconds to wait before restoring `gc-cons-threshold'.")
|
"Number of seconds to wait before restoring `gc-cons-threshold'.")
|
||||||
|
|
||||||
@@ -157,23 +165,26 @@ pre-early-init.el, and post-early-init.el.")
|
|||||||
|
|
||||||
(setq garbage-collection-messages minimal-emacs-debug)
|
(setq garbage-collection-messages minimal-emacs-debug)
|
||||||
|
|
||||||
(defun minimal-emacs--restore-gc-cons-threshold ()
|
(defun minimal-emacs--restore-gc-values ()
|
||||||
"Restore `gc-cons-threshold' to `minimal-emacs-gc-cons-threshold'."
|
"Restore garbage collection values to minimal-emacs.d values."
|
||||||
|
(setq gc-cons-threshold minimal-emacs-gc-cons-threshold)
|
||||||
|
(setq gc-cons-percentage minimal-emacs-gc-cons-percentage))
|
||||||
|
|
||||||
|
(defun minimal-emacs--restore-gc ()
|
||||||
|
"Restore garbage collection settings."
|
||||||
(if (bound-and-true-p minimal-emacs-gc-cons-threshold-restore-delay)
|
(if (bound-and-true-p minimal-emacs-gc-cons-threshold-restore-delay)
|
||||||
;; Defer garbage collection during initialization to avoid 2 collections.
|
;; Defer garbage collection during initialization to avoid 2 collections.
|
||||||
(run-at-time
|
(run-at-time minimal-emacs-gc-cons-threshold-restore-delay nil
|
||||||
minimal-emacs-gc-cons-threshold-restore-delay nil
|
#'minimal-emacs--restore-gc-values)
|
||||||
(lambda () (setq gc-cons-threshold minimal-emacs-gc-cons-threshold)))
|
(minimal-emacs--restore-gc-values)))
|
||||||
(setq gc-cons-threshold minimal-emacs-gc-cons-threshold)))
|
|
||||||
|
|
||||||
(if minimal-emacs-optimize-startup-gc
|
(if minimal-emacs-optimize-startup-gc
|
||||||
;; `gc-cons-threshold' is managed by minimal-emacs.d
|
;; `gc-cons-threshold' is managed by minimal-emacs.d
|
||||||
(add-hook 'emacs-startup-hook #'minimal-emacs--restore-gc-cons-threshold 105)
|
(add-hook 'emacs-startup-hook #'minimal-emacs--restore-gc 105)
|
||||||
;; gc-cons-threshold is not managed by minimal-emacs.d.
|
;; gc-cons-threshold is not managed by minimal-emacs.d.
|
||||||
;; If it is equal to `most-positive-fixnum', this indicates that the user has
|
(when (= gc-cons-threshold (- most-positive-fixnum 1))
|
||||||
;; not overridden the value in their `pre-early-init.el' configuration.
|
(setq gc-cons-threshold minimal-emacs--backup-gc-cons-threshold)
|
||||||
(when (= gc-cons-threshold most-positive-fixnum)
|
(setq gc-cons-percentage minimal-emacs--backup-gc-cons-percentage)))
|
||||||
(setq gc-cons-threshold minimal-emacs--backup-gc-cons-threshold)))
|
|
||||||
|
|
||||||
;;; Native compilation and Byte compilation
|
;;; Native compilation and Byte compilation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user