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,46 +247,46 @@ 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
`(lambda () (async-start
(let ((gc-cons-threshold ,doom-gc-cons-upper-limit) `(lambda ()
(doom-init-p t) (let ((gc-cons-threshold ,doom-gc-cons-upper-limit)
(noninteractive t) (doom-init-p t)
(load-path ',load-path) (noninteractive t)
(package-alist ',package-alist) (load-path ',load-path)
(package-archive-contents ',package-archive-contents) (package-alist ',package-alist)
(package-selected-packages ',package-selected-packages) (package-archive-contents ',package-archive-contents)
(doom-packages ',doom-packages) (package-selected-packages ',package-selected-packages)
(doom-modules ',doom-modules) (doom-packages ',doom-packages)
(quelpa-cache ',quelpa-cache) (doom-modules ',doom-modules)
(user-emacs-directory ,user-emacs-directory) (quelpa-cache ',quelpa-cache)
doom-private-dir) (user-emacs-directory ,user-emacs-directory)
(load ,(expand-file-name "core.el" doom-core-dir)) (packages ',pkgs)
(load ,(expand-file-name "autoload/packages.el" doom-core-dir)) doom-private-dir)
(require 'package) (load ,(expand-file-name "core.el" doom-core-dir))
(require 'quelpa) (load ,(expand-file-name "autoload/packages.el" doom-core-dir))
(doom-package-outdated-p ',pkg)))) (require 'package)
futures)) (require 'quelpa)
(delq nil (cl-delete-if-not #'doom-package-outdated-p packages))))
(append (mapcar #'doom-package-outdated-p elpa-pkgs) into futures
(mapcar #'async-get (reverse futures))))))) finally return
(delq nil
(append (mapcar #'doom-package-outdated-p .elpa)
(mapcan #'async-get futures))))))
;;;###autoload ;;;###autoload
(defun doom-get-orphaned-packages () (defun doom-get-orphaned-packages ()