From 51a9745f38b61fafa7d16caeb56e5746b395cd74 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 16 Sep 2022 19:06:15 +0200 Subject: [PATCH] perf: native-comp: use 1/4 of your cores instead of 1/2 The sudden spike in CPU and memory utilization alarms people, so I've reduced how many cores native-comp will use. In non-interactive sessions, it will use all of them, however (that is, when I later introduce an AOT switch). You can still override this by setting native-comp-async-jobs-number or comp-num-cpus yourself. I use advice instead of setting comp-num-cpus so that users to avoid trampling on default behavior, or attempts by the user to change them. --- lisp/doom.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lisp/doom.el b/lisp/doom.el index c75cb8749..556bb2ecb 100644 --- a/lisp/doom.el +++ b/lisp/doom.el @@ -490,7 +490,18 @@ Otherwise, `en/disable-command' (in novice.el.gz) is hardcoded to write them to ;; UX: Suppress compiler warnings and don't inundate users with their popups. ;; They are rarely more than warnings, so are safe to ignore. (setq native-comp-async-report-warnings-errors init-file-debug - native-comp-warning-on-missing-source init-file-debug)) + native-comp-warning-on-missing-source init-file-debug) + + ;; UX: By default, native-comp uses 100% of half your cores. If you're + ;; expecting this this should be no issue, but the sudden (and silent) spike + ;; of CPU and memory utilization can alarm folks, overheat laptops, or + ;; overwhelm less performant systems. + (define-advice comp-effective-async-max-jobs (:before (&rest _) set-default-cpus) + "Default to 1/4 of cores in interactive sessions and all of them otherwise." + (and (null comp-num-cpus) + (zerop native-comp-async-jobs-number) + (setq comp-num-cpus + (max 1 (/ (num-processors) (if noninteractive 1 4))))))) ;;; Suppress package.el ;; Since Emacs 27, package initialization occurs before `user-init-file' is