diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index 6db4b6591..963778e61 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -249,14 +249,22 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." ((add-hook hook fn -101))) fn))) -(defun doom-compile-function (fn &optional level) - "Compile FN, and natively, if possible." - (if (featurep 'native-compile) - (let ((native-comp-speed (or level native-comp-speed))) - (unless (subr-native-elisp-p (symbol-function fn)) - (native-compile fn))) - (unless (byte-code-function-p (symbol-function fn)) - (with-no-warnings (byte-compile fn))))) +(defun doom-compile-functions (&rest fns) + "Queue FNS to be byte/natively-compiled after a brief delay." + (with-memoization (get 'doom-compile-function 'timer) + (run-with-idle-timer + 1 t (fn! (when-let ((fn (pop fns)) + (fndef (indirect-function fn))) + (if (featurep 'native-compile) + (unless (subr-native-elisp-p fndef) + (doom-log "native-compile: Compiling %s" fn) + (native-compile fn)) + (unless (byte-code-function-p fndef) + (doom-log "byte-compile: Compiling %s" fn) + (byte-compile fn)))) + (unless fns + (cancel-timer (get 'doom-compile-function 'timer)) + (put 'doom-compile-function 'timer nil)))))) ;; diff --git a/modules/lang/emacs-lisp/autoload.el b/modules/lang/emacs-lisp/autoload.el index 7034ed71e..82e12cbcc 100644 --- a/modules/lang/emacs-lisp/autoload.el +++ b/modules/lang/emacs-lisp/autoload.el @@ -601,10 +601,11 @@ Adapted from 'https://www.reddit.com/r/emacs/comments/d7x7x8/finally_fixing_inde (desired-indent) (normal-indent)))))) -;; HACK: These functions are called often and as part of performance-sensitive -;; processes, so we compile them if the file isn't already compiled. -(mapc #'doom-compile-function '(+emacs-lisp-highlight-vars-and-faces - +emacs-lisp-truncate-pin - +emacs-lisp--calculate-lisp-indent-a)) +;; HACK: Quite a few functions here are called often, and so are especially +;; performance sensitive, so we compile this file on-demand, at least, until +;; Doom adds a formal compile step to 'doom sync'. +(doom-compile-functions #'+emacs-lisp-highlight-vars-and-faces + #'+emacs-lisp-truncate-pin + #'+emacs-lisp--calculate-lisp-indent-a) ;;; autoload.el ends here