From e4588af9697762e187c8caf4480a901362eb5420 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Mon, 8 Oct 2012 22:07:19 +0200 Subject: [PATCH] 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. --- guix/packages.scm | 13 ++++++++++--- 1 file 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 @@ (define (package-transitive-propagated-inputs package) (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)))