Refactor out map.el usage

After some profiling, it turns out map-put and map-delete are 5-7x
slower (more on Emacs 25) than delq, setf/alist-get and add-to-list for
small lists (under 250 items), which is exactly how I've been using
them.

The only caveat is alist-get's signature is different on Emacs 25, thus
a polyfill is necessary in core-lib.
This commit is contained in:
Henrik Lissner 2018-06-23 16:48:58 +02:00
parent f602a1f607
commit f6dc6ac74e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
29 changed files with 177 additions and 146 deletions

View file

@ -12,7 +12,7 @@
;; Like persistent-soft, caches assume a 2-tier structure, where all caches are
;; namespaced by location.
(defvar doom-cache-alists ()
(defvar doom-cache-alists '(t)
"An alist of alists, containing lists of variables for the doom cache library
to persist across Emacs sessions.")
@ -24,7 +24,7 @@ name under `pcache-directory' (by default a subdirectory under
(defun doom|save-persistent-cache ()
"Hook to run when an Emacs session is killed. Saves all persisted variables
listed in `doom-cache-alists' to files."
(dolist (alist doom-cache-alists)
(dolist (alist (butlast doom-cache-alists 1))
(cl-loop with key = (car alist)
for var in (cdr alist)
if (symbol-value var)
@ -54,8 +54,8 @@ Warning: this is incompatible with buffer-local variables."
(dolist (var variables)
(when (doom-cache-exists var location)
(set var (doom-cache-get var location))))
(map-put doom-cache-alists location
(append variables (cdr (assq location doom-cache-alists)))))
(setf (alist-get location doom-cache-alists)
(append variables (cdr (assq location doom-cache-alists)))))
;;;###autoload
(defun doom-cache-desist (location &optional variables)
@ -63,10 +63,11 @@ Warning: this is incompatible with buffer-local variables."
`doom-cache-alists', thus preventing them from being saved between sessions.
Does not affect the actual variables themselves or their values."
(if variables
(map-put doom-cache-alists location
(cl-set-difference (cdr (assq location doom-cache-alists))
variables))
(map-delete doom-cache-alists location)))
(setf (alist-get location doom-cache-alists)
(cl-set-difference (cdr (assq location doom-cache-alists))
variables))
(delq (assq location doom-cache-alists)
doom-cache-alists)))
;;;###autoload
(defun doom-cache-get (key &optional location)

View file

@ -345,7 +345,7 @@ example; the package name can be omitted)."
(package-install name))
(if (not (package-installed-p name))
(doom--delete-package-files name)
(map-put doom-packages name plist)
(setf (alist-get name alist) plist)
name)))
;;;###autoload
@ -388,9 +388,10 @@ package.el as appropriate."
(unless (package-installed-p name)
(user-error "%s isn't installed" name))
(let ((inhibit-message (not doom-debug-mode))
(spec (assq name quelpa-cache))
quelpa-p)
(when (assq name quelpa-cache)
(setq quelpa-cache (map-delete quelpa-cache name))
(when spec
(setq quelpa-cache (delq spec quelpa-cache))
(quelpa-save-cache)
(setq quelpa-p t))
(package-delete (cadr (assq name package-alist)) force-p)
@ -439,11 +440,11 @@ calls."
"Update `quelpa-cache' upon a successful `package-delete'."
(doom-initialize-packages)
(let ((name (package-desc-name desc)))
(when (and (not (package-installed-p name))
(assq name quelpa-cache))
(setq quelpa-cache (map-delete quelpa-cache name))
(quelpa-save-cache)
(doom--delete-package-files name))))
(unless (package-installed-p name)
(when-let* ((spec (assq name quelpa-cache)))
(setq quelpa-cache (delq spec quelpa-cache))
(quelpa-save-cache)
(doom--delete-package-files name)))))
;;