diff --git a/core/autoload/process.el b/core/autoload/process.el index 66d5d6a8c..46f4d28fc 100644 --- a/core/autoload/process.el +++ b/core/autoload/process.el @@ -40,3 +40,21 @@ Warning: freezes indefinitely on any stdin prompt." (sit-for 0.1)) (process-exit-status process)) (string-trim (buffer-string))))) + +(defvar doom-num-cpus nil) +;;;###autoload +(defun doom-num-cpus () + "Return the max number of processing units on this system. +Tries to be portable. Returns 1 if cannot be determined." + (or doom-num-cpus + (setq doom-num-cpus + (max + 1 (cond ((eq 'windows-nt system-type) + (or (ignore-errors + (string-to-number (getenv "NUMBER_OF_PROCESSORS"))) + 1)) + ((executable-find "nproc") + (string-to-number (cdr (doom-call-process "nproc")))) + ((and IS-MAC (executable-find "sysctl")) + (string-to-number (cdr (doom-call-process "sysctl" "-n" "hw.ncpu")))) + (t 1)))))) diff --git a/core/core.el b/core/core.el index 3c5e39125..27499a5f0 100644 --- a/core/core.el +++ b/core/core.el @@ -299,13 +299,7 @@ config.el instead." (defadvice! doom--comp-use-all-cores-a () :override #'comp-effective-async-max-jobs (if (zerop comp-async-jobs-number) - (or comp-num-cpus - (setf comp-num-cpus - (max 1 (cond ((eq 'windows-nt system-type) - (string-to-number (getenv "NUMBER_OF_PROCESSORS"))) - ((executable-find "nproc") - (string-to-number (cdr (doom-call-process "nproc")))) - (t 1))))) + (setq comp-num-cpus (doom-num-cpus)) comp-async-jobs-number))) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index ac682ee92..fc0d0f4f4 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -294,12 +294,9 @@ If rtags or rdm aren't available, fail silently instead of throwing a breaking e ccls-sem-highlight-method (if lsp-enable-semantic-highlighting ccls-sem-highlight-method)) (when (or IS-MAC IS-LINUX) - (let ((cpu-count-command (cond (IS-MAC '("sysctl" "-n" "hw.ncpu")) - (IS-LINUX '("nproc")) - (t (error "unreachable code"))))) - (setq ccls-initialization-options - `(:index (:trackDependency 1 - :threads ,(max 1 (/ (string-to-number (cdr (apply #'doom-call-process cpu-count-command))) 2))))))) + (setq ccls-initialization-options + `(:index (:trackDependency 1 + :threads ,(max 1 (/ (doom-num-cpus) 2)))))) (when IS-MAC (setq ccls-initialization-options (append ccls-initialization-options