From: "Ludovic Courtès" <ludo@gnu.org>
To: 48806@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>
Subject: [bug#48806] [PATCH 6/7] store: 'references/cached' now uses a per-session cache.
Date: Thu, 3 Jun 2021 09:34:00 +0200 [thread overview]
Message-ID: <20210603073401.13629-6-ludo@gnu.org> (raw)
In-Reply-To: <20210603073401.13629-1-ludo@gnu.org>
* guix/store.scm (%reference-cache): Remove.
(%reference-cache-id): New variable.
(references/cached): Rewrite in terms of it.
---
guix/store.scm | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/guix/store.scm b/guix/store.scm
index ea784a33d2..b761264ac0 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -1476,21 +1476,6 @@ 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/cached' 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/cached store item)
- "Like 'references', but cache results."
- (or (hash-ref %reference-cache item)
- (let ((references (references store item)))
- (hash-set! %reference-cache item references)
- references)))
-
(define* (fold-path store proc seed paths
#:optional (relatives (cut references store <>)))
"Call PROC for each of the RELATIVES of PATHS, exactly once, and return the
@@ -1810,6 +1795,26 @@ This is a mutating version that should be avoided. Prefer the functional
'set-store-connection-cache' instead, together with using %STORE-MONAD."
(vector-set! (store-connection-caches store) cache value))
+
+(define %reference-cache-id
+ ;; 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/cached' many
+ ;; times with the same arguments.
+ (allocate-store-connection-cache 'reference-cache))
+
+(define (references/cached store item)
+ "Like 'references', but cache results."
+ (let ((cache (store-connection-cache store %reference-cache-id)))
+ (match (vhash-assoc item cache)
+ ((_ . references)
+ references)
+ (#f
+ (let* ((references (references store item))
+ (cache (vhash-cons item references cache)))
+ (set-store-connection-cache! store %reference-cache-id cache)
+ references)))))
+
\f
;;;
;;; Store monad.
--
2.31.1
next prev parent reply other threads:[~2021-06-03 7:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-03 7:29 [bug#48806] [PATCH 0/7] Generalized cache support and improved graft caching Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 1/7] store: Support dynamic allocation of per-connection caches Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 2/7] store: Generalize cache lookup recording Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 3/7] grafts: Record cache lookups for profiling Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 4/7] grafts: Use SRFI-71 instead of SRFI-11 Ludovic Courtès
2021-06-03 7:33 ` [bug#48806] [PATCH 5/7] store: Remove 'references/substitutes' Ludovic Courtès
2021-06-03 7:34 ` Ludovic Courtès [this message]
2021-06-03 7:34 ` [bug#48806] [PATCH 7/7] grafts: Cache the derivation/graft mapping for the whole session Ludovic Courtès
2021-06-03 11:59 ` [bug#48806] [PATCH 0/7] Generalized cache support and improved graft caching Lars-Dominik Braun
2021-06-03 20:39 ` Ludovic Courtès
2021-06-08 7:34 ` bug#48806: " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210603073401.13629-6-ludo@gnu.org \
--to=ludo@gnu.org \
--cc=48806@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.