summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorAndrea Corallo <akrl@sdf.org>2020-03-15 20:17:15 +0000
committerAndrea Corallo <akrl@sdf.org>2020-03-16 22:56:36 +0000
commit0b28bf0529cc6e6125924cc54ba8de30f3872ab9 (patch)
tree6a8df39df29e5547187873dc8d6866becbc08b8d /lisp/emacs-lisp
parent92fdfa4b5a468d9560e21a5a22a83847fd8ca2c7 (diff)
downloademacs-0b28bf0529cc6e6125924cc54ba8de30f3872ab9.tar.gz
emacs-0b28bf0529cc6e6125924cc54ba8de30f3872ab9.tar.bz2
emacs-0b28bf0529cc6e6125924cc54ba8de30f3872ab9.zip
* comp.el: Estimate async worker number using system CPU number
This only when `comp-async-jobs-number' is 0 (default).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/comp.el21
1 files changed, 17 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index f47d3ce470e..68d3b8b2c73 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -85,8 +85,9 @@ performed at `comp-speed' > 0."
:type 'list
:group 'comp)
-(defcustom comp-async-jobs-number 2
- "Default number of processes used for async compilation."
+(defcustom comp-async-jobs-number 0
+ "Default number of processes used for async compilation.
+When zero use half of the CPUs or at least one."
:type 'fixnum
:group 'comp)
@@ -2082,13 +2083,25 @@ processes from `comp-async-processes'"
(cl-delete-if-not #'process-live-p comp-async-processes))
(length comp-async-processes))
+(let (num-cpus)
+ (defun comp-effective-async-max-jobs ()
+ "Compute the effective number of async jobs."
+ (if (zerop comp-async-jobs-number)
+ (or num-cpus
+ (setf num-cpus
+ ;; Half of the CPUs or at least one.
+ ;; FIXME portable?
+ (max 1 (/ (string-to-number (shell-command-to-string "nproc"))
+ 2))))
+ comp-async-jobs-number)))
+
(defun comp-run-async-workers ()
"Start compiling files from `comp-files-queue' asynchronously.
When compilation is finished, run `comp-async-all-done-hook' and
display a message."
(if (or comp-files-queue
(> (comp-async-runnings) 0))
- (unless (>= (comp-async-runnings) comp-async-jobs-number)
+ (unless (>= (comp-async-runnings) (comp-effective-async-max-jobs))
(cl-loop
for source-file = (pop comp-files-queue)
while source-file
@@ -2119,7 +2132,7 @@ display a message."
(accept-process-output process)
(comp-run-async-workers)))))
(push process comp-async-processes))
- when (>= (comp-async-runnings) comp-async-jobs-number)
+ when (>= (comp-async-runnings) (comp-effective-async-max-jobs))
do (cl-return)))
;; No files left to compile and all processes finished.
(let ((msg "Compilation finished."))