Move GC optimization to init.el
And reformat core.el
This commit is contained in:
parent
2cb5d895d7
commit
2525822791
2 changed files with 29 additions and 24 deletions
37
core/core.el
37
core/core.el
|
@ -216,6 +216,17 @@ Doom was setup, which may cause problems.")
|
|||
url-configuration-directory (concat doom-etc-dir "url/")
|
||||
gamegrid-user-score-file-directory (concat doom-etc-dir "games/"))
|
||||
|
||||
(defun doom*symbol-file (orig-fn symbol &optional type)
|
||||
"If a `doom-file' symbol property exists on SYMBOL, use that instead of the
|
||||
original value of `symbol-file'."
|
||||
(or (if (symbolp symbol) (get symbol 'doom-file))
|
||||
(funcall orig-fn symbol type)))
|
||||
(advice-add #'symbol-file :around #'doom*symbol-file)
|
||||
|
||||
|
||||
;;
|
||||
;;; Minor mode version of `auto-mode-alist'
|
||||
|
||||
(defvar doom-auto-minor-mode-alist '()
|
||||
"Alist mapping filename patterns to corresponding minor mode functions, like
|
||||
`auto-mode-alist'. All elements of this alist are checked, meaning you can
|
||||
|
@ -239,12 +250,9 @@ enable multiple minor modes for the same regexp.")
|
|||
(setq alist (cdr alist))))))
|
||||
(add-hook 'find-file-hook #'doom|enable-minor-mode-maybe)
|
||||
|
||||
(defun doom*symbol-file (orig-fn symbol &optional type)
|
||||
"If a `doom-file' symbol property exists on SYMBOL, use that instead of the
|
||||
original value of `symbol-file'."
|
||||
(or (if (symbolp symbol) (get symbol 'doom-file))
|
||||
(funcall orig-fn symbol type)))
|
||||
(advice-add #'symbol-file :around #'doom*symbol-file)
|
||||
|
||||
;;
|
||||
;;; MODE-local-vars-hook
|
||||
|
||||
;; File+dir local variables are initialized after the major mode and its hooks
|
||||
;; have run. If you want hook functions to be aware of these customizations, add
|
||||
|
@ -272,23 +280,6 @@ original value of `symbol-file'."
|
|||
(add-hook 'find-file-not-found-functions #'doom|create-non-existent-directories)
|
||||
|
||||
|
||||
;;
|
||||
;;; Garbage collector optimizations
|
||||
|
||||
;; To speed up minibuffer commands (like helm and ivy), defer garbage collection
|
||||
;; when the minibuffer is active. It may mean a pause when finished, but that's
|
||||
;; acceptable instead of pauses during.
|
||||
(defun doom|defer-garbage-collection ()
|
||||
(setq gc-cons-threshold doom-gc-cons-upper-limit))
|
||||
(defun doom|restore-garbage-collection ()
|
||||
(setq gc-cons-threshold doom-gc-cons-threshold))
|
||||
(add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection)
|
||||
(add-hook 'minibuffer-exit-hook #'doom|restore-garbage-collection)
|
||||
|
||||
;; GC all sneaky breeky like
|
||||
(add-hook 'focus-out-hook 'garbage-collect)
|
||||
|
||||
|
||||
;;
|
||||
;;; Incremental lazy-loading
|
||||
|
||||
|
|
16
init.el
16
init.el
|
@ -45,7 +45,21 @@ decrease this. If you experience stuttering, increase this.")
|
|||
;; Do this on idle timer to defer a possible GC pause that could result; also
|
||||
;; allows deferred packages to take advantage of these optimizations.
|
||||
(run-with-idle-timer
|
||||
3 nil (lambda () (setq-default gc-cons-threshold doom-gc-cons-threshold))))
|
||||
3 nil
|
||||
(lambda ()
|
||||
(setq-default gc-cons-threshold doom-gc-cons-threshold)
|
||||
;; To speed up minibuffer commands (like helm and ivy), we defer garbage
|
||||
;; collection while the minibuffer is active.
|
||||
(defun doom|defer-garbage-collection ()
|
||||
(setq gc-cons-threshold doom-gc-cons-upper-limit))
|
||||
(defun doom|restore-garbage-collection ()
|
||||
;; Defer it so that commands launched from the minibuffer can enjoy the
|
||||
;; benefits.
|
||||
(run-at-time 1 nil (lambda () (setq gc-cons-threshold doom-gc-cons-threshold))))
|
||||
(add-hook 'minibuffer-setup-hook #'doom|defer-garbage-collection)
|
||||
(add-hook 'minibuffer-exit-hook #'doom|restore-garbage-collection)
|
||||
;; GC all sneaky breeky like
|
||||
(add-hook 'focus-out-hook #'garbage-collect))))
|
||||
|
||||
|
||||
(if (ignore-errors (or after-init-time noninteractive))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue