[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/06: store: 'references/substitutes' caches its results.
From: |
Ludovic Courtès |
Subject: |
02/06: store: 'references/substitutes' caches its results. |
Date: |
Mon, 14 Mar 2016 22:35:10 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit f09aea1b58b3ef961d3cc712f116fe4617bc8f90
Author: Ludovic Courtès <address@hidden>
Date: Mon Mar 14 16:53:38 2016 +0100
store: 'references/substitutes' caches its results.
* guix/store.scm (%reference-cache): New variable.
(references/substitutes): Use it.
---
guix/store.scm | 18 +++++++++++++++---
1 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/guix/store.scm b/guix/store.scm
index a220b6e..0124873 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -726,14 +726,23 @@ error if there is no such root."
"Return the list of references of PATH."
store-path-list))
+(define %reference-cache
+ ;; Brute-force cache mapping store items to their list of references.
+ ;; Caching matters because when building a profile in the presence of
+ ;; grafts, we keep calling 'graft-derivation', which in turn calls
+ ;; 'references/substitutes' many times with the same arguments. Ideally we
+ ;; would use a cache associated with the daemon connection instead (XXX).
+ (make-hash-table 100))
+
(define (references/substitutes store items)
"Return the list of list of references of ITEMS; the result has the same
length as ITEMS. Query substitute information for any item missing from the
store at once. Raise a '&nix-protocol-error' exception if reference
information for one of ITEMS is missing."
(let* ((local-refs (map (lambda (item)
- (guard (c ((nix-protocol-error? c) #f))
- (references store item)))
+ (or (hash-ref %reference-cache item)
+ (guard (c ((nix-protocol-error? c) #f))
+ (references store item))))
items))
(missing (fold-right (lambda (item local-ref result)
(if local-ref
@@ -757,7 +766,10 @@ the list of references")
(result '()))
(match items
(()
- (reverse result))
+ (let ((result (reverse result)))
+ (for-each (cut hash-set! %reference-cache <> <>)
+ items result)
+ result))
((item items ...)
(match local-refs
((#f tail ...)
- branch master updated (6e6a040 -> 264fded), Ludovic Courtès, 2016/03/14
- 03/06: substitute: Remove dead code., Ludovic Courtès, 2016/03/14
- 06/06: grafts: Update the narinfo cache before building a derivation., Ludovic Courtès, 2016/03/14
- 01/06: size: Disable grafts., Ludovic Courtès, 2016/03/14
- 04/06: http-client: Add #:keep-alive? parameter., Ludovic Courtès, 2016/03/14
- 05/06: substitute: Keep the initial connection alive., Ludovic Courtès, 2016/03/14
- 02/06: store: 'references/substitutes' caches its results.,
Ludovic Courtès <=