Refactor doom-get-outdated-packages

Partitions quelpa packages so there are 4 threads tops.
This commit is contained in:
Henrik Lissner 2019-03-06 18:18:51 -05:00
parent 2d353b849c
commit 31688c921d
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -247,24 +247,22 @@ If INCLUDE-FROZEN-P is non-nil, check frozen packages as well.
Used by `doom-packages-update'." Used by `doom-packages-update'."
(doom-initialize-packages t) (doom-initialize-packages t)
(doom-refresh-packages-maybe doom-debug-mode) (doom-refresh-packages-maybe doom-debug-mode)
(require 'async) (let-alist
(let (quelpa-pkgs elpa-pkgs) (seq-group-by
;; Separate quelpa from elpa packages #'doom-package-backend
(dolist (pkg (mapcar #'car package-alist)) (cl-loop for package in (mapcar #'car package-alist)
(when (and (or (not (doom-package-prop pkg :freeze 'eval)) when (and (or (not (doom-package-prop package :freeze 'eval))
include-frozen-p) include-frozen-p)
(not (doom-package-prop pkg :ignore 'eval)) (not (doom-package-prop package :ignore 'eval))
(not (doom-package-different-backend-p pkg))) (not (doom-package-different-backend-p package)))
(push pkg collect package))
(if (eq (doom-package-backend pkg) 'quelpa)
quelpa-pkgs
elpa-pkgs))))
;; The bottleneck in this process is quelpa's version checks, so check them ;; The bottleneck in this process is quelpa's version checks, so check them
;; asynchronously. ;; asynchronously.
(let (futures) (cl-loop with partitions = (/ (length .quelpa) 4)
(dolist (pkg quelpa-pkgs) for pkgs in (seq-partition .quelpa partitions)
(doom-log "New thread for: %s" pkg) do (doom-log "New thread for: %s" pkgs)
(push (async-start and collect
(async-start
`(lambda () `(lambda ()
(let ((gc-cons-threshold ,doom-gc-cons-upper-limit) (let ((gc-cons-threshold ,doom-gc-cons-upper-limit)
(doom-init-p t) (doom-init-p t)
@ -277,16 +275,18 @@ Used by `doom-packages-update'."
(doom-modules ',doom-modules) (doom-modules ',doom-modules)
(quelpa-cache ',quelpa-cache) (quelpa-cache ',quelpa-cache)
(user-emacs-directory ,user-emacs-directory) (user-emacs-directory ,user-emacs-directory)
(packages ',pkgs)
doom-private-dir) doom-private-dir)
(load ,(expand-file-name "core.el" doom-core-dir)) (load ,(expand-file-name "core.el" doom-core-dir))
(load ,(expand-file-name "autoload/packages.el" doom-core-dir)) (load ,(expand-file-name "autoload/packages.el" doom-core-dir))
(require 'package) (require 'package)
(require 'quelpa) (require 'quelpa)
(doom-package-outdated-p ',pkg)))) (cl-delete-if-not #'doom-package-outdated-p packages))))
futures)) into futures
finally return
(delq nil (delq nil
(append (mapcar #'doom-package-outdated-p elpa-pkgs) (append (mapcar #'doom-package-outdated-p .elpa)
(mapcar #'async-get (reverse futures))))))) (mapcan #'async-get futures))))))
;;;###autoload ;;;###autoload
(defun doom-get-orphaned-packages () (defun doom-get-orphaned-packages ()