Browse Source

packages: Fix and optimize memoization of `package-derivation'.

* guix/packages.scm (%derivation-cache): Pass an initial size of 100.
  (cache): Use `hashq-set!', and use a SYSTEM/DRV pair as the value.
  (cached-derivation): Update accordingly.
gn-latest-20200428
Ludovic Courtès 9 years ago
parent
commit
e4588af969
  1. 13
      guix/packages.scm

13
guix/packages.scm

@ -206,16 +206,23 @@ recursively."
(define %derivation-cache
;; Package to derivation-path mapping.
(make-weak-key-hash-table))
(make-weak-key-hash-table 100))
(define (cache package system drv)
"Memoize DRV as the derivation of PACKAGE on SYSTEM."
(hash-set! %derivation-cache (cons package system) drv)
;; Use `hashq-set!' instead of `hash-set!' because `hash' returns the
;; same value for all structs (as of Guile 2.0.6), and because pointer
;; equality is sufficient in practice.
(hashq-set! %derivation-cache package `((,system . ,drv)))
drv)
(define (cached-derivation package system)
"Return the cached derivation path of PACKAGE for SYSTEM, or #f."
(hash-ref %derivation-cache (cons package system)))
(match (hashq-ref %derivation-cache package)
((alist ...)
(assoc-ref alist system))
(#f #f)))
(define* (package-derivation store package
#:optional (system (%current-system)))

Loading…
Cancel
Save