aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-10-08 22:07:19 +0200
committerLudovic Courtès <ludo@gnu.org>2012-10-08 22:07:19 +0200
commite4588af9697762e187c8caf4480a901362eb5420 (patch)
treea1237de3d8236463fbc3058bfcf57f1a56d9f022
parentead1f1086d1d64657ab710f4340dc5e4f79ea045 (diff)
downloadguix-e4588af9697762e187c8caf4480a901362eb5420.tar
guix-e4588af9697762e187c8caf4480a901362eb5420.tar.gz
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.
-rw-r--r--guix/packages.scm13
1 files changed, 10 insertions, 3 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index 8fb77e5fd7..4b687717e4 100644
--- a/guix/packages.scm
+++ b/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)))