From unknown Fri Aug 15 16:23:44 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#55398] [PATCH 0/3] Improve store caching; improve 'map/accumulate-builds' performance Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 13 May 2022 15:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 55398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55398@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.165245399830965 (code B ref -1); Fri, 13 May 2022 15:00:03 +0000 Received: (at submit) by debbugs.gnu.org; 13 May 2022 14:59:58 +0000 Received: from localhost ([127.0.0.1]:44519 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWlp-00083N-My for submit@debbugs.gnu.org; Fri, 13 May 2022 10:59:57 -0400 Received: from lists.gnu.org ([209.51.188.17]:47606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWln-00083F-Vr for submit@debbugs.gnu.org; Fri, 13 May 2022 10:59:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWln-0000Tb-Ns for guix-patches@gnu.org; Fri, 13 May 2022 10:59:55 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWln-0000NM-A2; Fri, 13 May 2022 10:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=sVpWpPSPLiNNg1U6tvP6nEFMs20+s4hKr6O/98nhAco=; b=VEKMDgfpW6Y0P7 fwpTaIzrPK+kMWMsSvWaaCJzx1qtE8bG5KCbYJBqTo50//5GQhzP6Sg37VrLsMDl7u9LdEN4qqwpn 4F6JdlpV4BElZN9fVL76wlbNOy1MlTpj5rZ02ShapwG3vNOav/12h9GD6bvcIoIKb9Xb4NvQfKEcD LF/qK2adkCSL1GoyxYpgo/YlefvCGe08Rh5dTBMSNlbE5DsXNZaJidZLX7xEXsVTnGnDZKTjiuNQT W2PuKEQvGSehs7/Lcx/fMUrMWx2sNCMMJ8hg8i1zwBO4OeASAJnyDTgyLBZtLElkxRq+uaJP7EJnu c0A6xTtMgE3V9VvL4V9A==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44954 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npWlm-0008OV-6b; Fri, 13 May 2022 10:59:54 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 May 2022 16:59:47 +0200 Message-Id: <20220513145947.11951-1-ludo@gnu.org> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello! The first patch improves cache handling, providing a generic way to trace caches. The second patch adds a separate package/graft cache, as was previously suggested in a comment. The cache hit rate can be seen by setting GUIX_PROFILING: --8<---------------cut here---------------start------------->8--- $ time GUIX_PROFILING=package-graft-cache ./pre-inst-env guix home build -v1 -n ~/src/configuration/home-config.scm 28.5 MB would be downloaded Package Graft Cache: fresh caches: 1 lookups: 794 hits: 784 (98.7%) cache size: 10 entries real 0m7.953s user 0m9.091s sys 0m0.291s --8<---------------cut here---------------end--------------->8--- The last patch improves performance in the presence of grafts by trimming exploration of the call tree in ‘map/accumulate-builds’. This is very much a heuristic, but it does help significantly for ‘guix system’, ‘guix home’, or ‘guix package’ with many packages. Thoughts? Ludo’. Ludovic Courtès (3): store: 'mcached' users can specify a cache ID. packages: Use separate package/graft cache. store: Use a decaying cutoff in 'map/accumulate-builds'. guix/packages.scm | 12 ++++-- guix/store.scm | 104 +++++++++++++++++++++++++++++++++------------- 2 files changed, 84 insertions(+), 32 deletions(-) base-commit: 0b4300d4fd8c972f0cb9d6751fc824b9a065b780 -- 2.36.0 From unknown Fri Aug 15 16:23:44 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#55398] [PATCH 1/3] store: 'mcached' users can specify a cache ID. References: <20220513145947.11951-1-ludo@gnu.org> In-Reply-To: <20220513145947.11951-1-ludo@gnu.org> Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 13 May 2022 15:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55398@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 55398-submit@debbugs.gnu.org id=B55398.165245406531285 (code B ref 55398); Fri, 13 May 2022 15:02:01 +0000 Received: (at 55398) by debbugs.gnu.org; 13 May 2022 15:01:05 +0000 Received: from localhost ([127.0.0.1]:44529 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmv-00088W-22 for submit@debbugs.gnu.org; Fri, 13 May 2022 11:01:05 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41696) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmt-00087e-74 for 55398@debbugs.gnu.org; Fri, 13 May 2022 11:01:03 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34260) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWmn-0000qc-UG; Fri, 13 May 2022 11:00:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=5wv6zWEPreUQYSoydtDQrXQzrNheqrjDBwn/ng5IOYI=; b=fImItVdZQ3J3WK oH999c86DDBd3WziWblgrIjJtMVBGoPIMN4NV74aTn0FgGI4AFawcAmE1fyU11+LC4zT5WiGTzup+ tCaWytEMPv/OeLVxmIB/msWlJ4h5lxphIRKouLCDzAUQ0mgxrlljC7LncHexA5NynH4wMiTABBScY F/9157v6S9VtSiqVmq9OCi+58X+DjwgcZrGyeQiJ4ezhSGC6d7NOHyWfsndymPvHY7oU+Ju5OiZvQ F3DKHy5cKczAUC/3lbcPpoR8R1xMcH3lz8NCim4m+FgEuQbZ9s/O43fIulZILRn1b2ZZ/3Vn4c7US u4Zdhy3mfg5u6HqeMzow==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44956 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npWmn-0002Q4-GF; Fri, 13 May 2022 11:00:57 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 May 2022 17:00:42 +0200 Message-Id: <20220513150044.11991-1-ludo@gnu.org> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Users of 'mcached' can now specify a cache ID; furthermore, the cache hit rate is automatically recorded for all the caches accessed with 'mcached'. * guix/store.scm (%max-store-connection-caches) (%store-connection-cache-names): New variables. (recorder-for-cache): New procedure. (record-cache-lookup!): Add 'cache-id' parameter and rewrite in terms of 'recorder-for-cache'. (lookup-cached-object): Add 'cache-id' parameter and honor it. (%mcached): Add #:cache parameter and honor it. (mcached): Add '=>' keyword and corresponding clauses. --- guix/store.scm | 65 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/guix/store.scm b/guix/store.scm index 1d176fb99d..220901f6ce 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2012-2022 Ludovic Courtès ;;; Copyright © 2018 Jan Nieuwenhuizen ;;; Copyright © 2019, 2020 Mathieu Othacehe ;;; Copyright © 2020 Florian Pelz @@ -1793,6 +1793,14 @@ (define-operation (clear-failed-paths (store-path-list items)) ;; the 'caches' vector of . (define %store-connection-caches (make-atomic-box 0)) +(define %max-store-connection-caches + ;; Maximum number of caches returned by 'allocate-store-connection-cache'. + 32) + +(define %store-connection-cache-names + ;; Mapping of cache ID to symbol. + (make-vector %max-store-connection-caches)) + (define (allocate-store-connection-cache name) "Allocate a new cache for store connections and return its identifier. Said identifier can be passed as an argument to " @@ -1800,7 +1808,9 @@ (define (allocate-store-connection-cache name) (let ((previous (atomic-box-compare-and-swap! %store-connection-caches current (+ current 1)))) (if (= previous current) - current + (begin + (vector-set! %store-connection-cache-names current name) + current) (loop current))))) (define %object-cache-id @@ -1926,16 +1936,37 @@ (define (cache-lookup-recorder component title) (lambda (x y) #t))) -(define record-cache-lookup! - (cache-lookup-recorder "object-cache" "Store object cache")) +(define recorder-for-cache + (let ((recorders (make-vector %max-store-connection-caches))) + (lambda (cache-id) + "Return a procedure to record lookup stats for CACHE-ID." + (match (vector-ref recorders cache-id) + ((? unspecified?) + (let* ((name (symbol->string + (vector-ref %store-connection-cache-names cache-id))) + (description + (string-titlecase + (string-map (match-lambda + (#\- #\space) + (chr chr)) + name)))) + (let ((proc (cache-lookup-recorder name description))) + (vector-set! recorders cache-id proc) + proc))) + (proc proc))))) -(define-inlinable (lookup-cached-object object keys vhash-fold*) - "Return the cached object in the store connection corresponding to OBJECT +(define (record-cache-lookup! cache-id value cache) + "Record the lookup of VALUE in CACHE-ID, whose current value is CACHE." + (let ((record! (recorder-for-cache cache-id))) + (record! value cache))) + +(define-inlinable (lookup-cached-object cache-id object keys vhash-fold*) + "Return the object in store cache CACHE-ID corresponding to OBJECT and KEYS; use VHASH-FOLD* to look for OBJECT in the cache. KEYS is a list of additional keys to match against, and which are compared with 'equal?'. Return #f on failure and the cached result otherwise." (lambda (store) - (let* ((cache (store-connection-cache store %object-cache-id)) + (let* ((cache (store-connection-cache store cache-id)) ;; Escape as soon as we find the result. This avoids traversing ;; the whole vlist chain and significantly reduces the number of @@ -1949,40 +1980,50 @@ (define-inlinable (lookup-cached-object object keys vhash-fold*) result)))) #f object cache)))) - (record-cache-lookup! value cache) + (record-cache-lookup! cache-id value cache) (values value store)))) (define* (%mcached mthunk object #:optional (keys '()) #:key + (cache %object-cache-id) (vhash-cons vhash-consq) (vhash-fold* vhash-foldq*)) "Bind the monadic value returned by MTHUNK, which supposedly corresponds to OBJECT/KEYS, or return its cached value. Use VHASH-CONS to insert OBJECT into the cache, and VHASH-FOLD* to look it up." - (mlet %store-monad ((cached (lookup-cached-object object keys + (mlet %store-monad ((cached (lookup-cached-object cache object keys vhash-fold*))) (if cached (return cached) (>>= (mthunk) (lambda (result) (cache-object-mapping object keys result + #:cache cache #:vhash-cons vhash-cons)))))) (define-syntax mcached - (syntax-rules (eq? equal?) + (syntax-rules (eq? equal? =>) "Run MVALUE, which corresponds to OBJECT/KEYS, and cache it; or return the value associated with OBJECT/KEYS in the store's object cache if there is one." - ((_ eq? mvalue object keys ...) + ((_ eq? (=> cache) mvalue object keys ...) (%mcached (lambda () mvalue) object (list keys ...) + #:cache cache #:vhash-cons vhash-consq #:vhash-fold* vhash-foldq*)) - ((_ equal? mvalue object keys ...) + ((_ equal? (=> cache) mvalue object keys ...) (%mcached (lambda () mvalue) object (list keys ...) + #:cache cache #:vhash-cons vhash-cons #:vhash-fold* vhash-fold*)) + ((_ eq? mvalue object keys ...) + (mcached eq? (=> %object-cache-id) + mvalue object keys ...)) + ((_ equal? mvalue object keys ...) + (mcached equal? (=> %object-cache-id) + mvalue object keys ...)) ((_ mvalue object keys ...) (mcached eq? mvalue object keys ...)))) -- 2.36.0 From unknown Fri Aug 15 16:23:44 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#55398] [PATCH 2/3] packages: Use separate package/graft cache. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 13 May 2022 15:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55398@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 55398-submit@debbugs.gnu.org id=B55398.165245406831297 (code B ref 55398); Fri, 13 May 2022 15:02:02 +0000 Received: (at 55398) by debbugs.gnu.org; 13 May 2022 15:01:08 +0000 Received: from localhost ([127.0.0.1]:44531 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmx-00088h-Ls for submit@debbugs.gnu.org; Fri, 13 May 2022 11:01:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41704) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmt-00087h-QS for 55398@debbugs.gnu.org; Fri, 13 May 2022 11:01:04 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34262) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWmo-0000rH-H3; Fri, 13 May 2022 11:00:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=0cQFKIpDUfvrcCbC9mkJ6n1Bs20ZI4Mt7Tm0RlaPSiw=; b=F7b7jBxOSBtNzCzqR0i2 0eMUtdVJ41aY3zprKFvNt6s8kabCG8QtGHaV5Pl6D5O2XNZhzjS9MPQ4HAw3ZRnkKsAswk+fAY6I6 /wmv2d/9Cobz/jsEcxmSwJ7kBTku95CdXQn0z22JZnoChWe8AHHEHXrT00iPw9dmoC2otHEtolsws 7eKNAIR8jn7UbdZsK5KAEN1gNK7a6VUZLGWtQ6FfieSwgUJyqHL/cUKcN+8ZRGMO2ZChNOXpba35F WFwFtCccfAk5GWI1iZmJYVHX4L0itn3pSAcZegrF4sg3uS0Z1AGD97szCjDTMH3qbtiL2a1mRXpxF VScEWpATABiHdw==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44956 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npWmo-0002Q4-4D; Fri, 13 May 2022 11:00:58 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 May 2022 17:00:43 +0200 Message-Id: <20220513150044.11991-2-ludo@gnu.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220513150044.11991-1-ludo@gnu.org> References: <20220513150044.11991-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) * guix/packages.scm (%package-graft-cache): New variable. (input-graft): Add (=> %package-graft-cache). --- guix/packages.scm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/guix/packages.scm b/guix/packages.scm index a79b36d03d..7ee65e9b6b 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -1618,6 +1618,11 @@ (define* (package->bag package #:optional (&package-error (package package)))))))))))) +(define %package-graft-cache + ;; Cache mapping records to records, for packages that + ;; have a replacement. + (allocate-store-connection-cache 'package-graft-cache)) + (define (input-graft system) "Return a monadic procedure that, given a package with a graft, returns a graft, and #f otherwise." @@ -1626,9 +1631,8 @@ (define (input-graft system) (((? package? package) output) (let ((replacement (package-replacement package))) (if replacement - ;; XXX: We should use a separate cache instead of abusing the - ;; object cache. - (mcached (mlet %store-monad ((orig (package->derivation package system + (mcached eq? (=> %package-graft-cache) + (mlet %store-monad ((orig (package->derivation package system #:graft? #f)) (new (package->derivation replacement system #:graft? #t))) @@ -1637,7 +1641,7 @@ (define (input-graft system) (origin-output output) (replacement new) (replacement-output output)))) - package 'graft output system) + package output system) (return #f)))) (_ (return #f))))) -- 2.36.0 From unknown Fri Aug 15 16:23:44 2025 X-Loop: help-debbugs@gnu.org Subject: [bug#55398] [PATCH 3/3] store: Use a decaying cutoff in 'map/accumulate-builds'. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 13 May 2022 15:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55398@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 55398-submit@debbugs.gnu.org id=B55398.165245406831303 (code B ref 55398); Fri, 13 May 2022 15:02:02 +0000 Received: (at 55398) by debbugs.gnu.org; 13 May 2022 15:01:08 +0000 Received: from localhost ([127.0.0.1]:44533 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmy-00088k-0D for submit@debbugs.gnu.org; Fri, 13 May 2022 11:01:08 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41710) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWmu-00087j-E1 for 55398@debbugs.gnu.org; Fri, 13 May 2022 11:01:04 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWmp-0000rW-4j; Fri, 13 May 2022 11:00:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=t3Vx509AUNLNgKhLzt8Bx8yVwa6BPUi/NXUEHGYB8F0=; b=LlQTrEnqiaojAbcmMy54 9a73FDhuFCrSlPke5/hmqOo1sfgiBiDuCV6P56zpW5pOrCdOA5nfFzCIhTlSBlJxjQeT4HK49XKvn ZOyRRa9YbY226zij5+q7jqD2IOmdSPZ/lMGvJTwwxhybE0Aj8uMIINXOx1fCEpwfIa/VuTATQ3NY1 +DZrv68vWVAWbBWHbfHsVk6nTMe7+d0aFkhikwxzqbYWS/J6XA4LMDtoEsO+jecpMvKUeo/1ARtBK 5jrjUR+EgoQE6hFE77GthaELUsfNMECWZeunVKy6fICuxr3i5HGH7e5ygmieVrq1cAlXU3x4fP4/V 2LE8+CCMvpsV7Q==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44956 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npWmo-0002Q4-O3; Fri, 13 May 2022 11:00:58 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 13 May 2022 17:00:44 +0200 Message-Id: <20220513150044.11991-3-ludo@gnu.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220513150044.11991-1-ludo@gnu.org> References: <20220513150044.11991-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This reduces the wall-clock time of: ./pre-inst-env guix system vm gnu/system/examples/desktop.tmpl -n from 2m13s to 53s (the timings depend on which derivations have already been built and are in store; in this case, many were missing). * guix/store.scm (default-cutoff): New variable. (map/accumulate-builds): Use it. Parameterize it in recursive calls to have decaying cutoff. --- guix/store.scm | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/guix/store.scm b/guix/store.scm index 220901f6ce..a3240eb2e0 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -1362,8 +1362,12 @@ (define (build-accumulator expected-store) (unresolved things continue) (continue #t)))) +(define default-cutoff + ;; Default cutoff parameter for 'map/accumulate-builds'. + (make-parameter 32)) + (define* (map/accumulate-builds store proc lst - #:key (cutoff 30)) + #:key (cutoff (default-cutoff))) "Apply PROC over each element of LST, accumulating 'build-things' calls and coalescing them into a single call. @@ -1377,21 +1381,24 @@ (define accumulator (build-accumulator store)) (define-values (result rest) - (let loop ((lst lst) - (result '()) - (unresolved 0)) - (match lst - ((head . tail) - (match (with-build-handler accumulator - (proc head)) - ((? unresolved? obj) - (if (>= unresolved cutoff) - (values (reverse (cons obj result)) tail) - (loop tail (cons obj result) (+ 1 unresolved)))) - (obj - (loop tail (cons obj result) unresolved)))) - (() - (values (reverse result) lst))))) + ;; Have the default cutoff decay as we go deeper in the call stack to + ;; avoid pessimal behavior. + (parameterize ((default-cutoff (quotient cutoff 2))) + (let loop ((lst lst) + (result '()) + (unresolved 0)) + (match lst + ((head . tail) + (match (with-build-handler accumulator + (proc head)) + ((? unresolved? obj) + (if (>= unresolved cutoff) + (values (reverse (cons obj result)) tail) + (loop tail (cons obj result) (+ 1 unresolved)))) + (obj + (loop tail (cons obj result) unresolved)))) + (() + (values (reverse result) lst)))))) (match (append-map (lambda (obj) (if (unresolved? obj) -- 2.36.0 From unknown Fri Aug 15 16:23:44 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Subject: bug#55398: closed (Re: bug#55398: [PATCH 0/3] Improve store caching; improve 'map/accumulate-builds' performance) Message-ID: References: <875ym21ohh.fsf@gnu.org> <20220513145947.11951-1-ludo@gnu.org> X-Gnu-PR-Message: they-closed 55398 X-Gnu-PR-Package: guix-patches X-Gnu-PR-Keywords: patch Reply-To: 55398@debbugs.gnu.org Date: Wed, 18 May 2022 22:11:01 +0000 Content-Type: multipart/mixed; boundary="----------=_1652911861-24194-1" This is a multi-part message in MIME format... ------------=_1652911861-24194-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #55398: [PATCH 0/3] Improve store caching; improve 'map/accumulate-builds' = performance which was filed against the guix-patches package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 55398@debbugs.gnu.org. --=20 55398: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D55398 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1652911861-24194-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 55398-done) by debbugs.gnu.org; 18 May 2022 22:10:28 +0000 Received: from localhost ([127.0.0.1]:33835 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nrRsC-0006HW-JT for submit@debbugs.gnu.org; Wed, 18 May 2022 18:10:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33524) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nrRsA-0006HI-9v for 55398-done@debbugs.gnu.org; Wed, 18 May 2022 18:10:26 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrRs5-0005cB-4Z for 55398-done@debbugs.gnu.org; Wed, 18 May 2022 18:10:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=RVtp+sRPNlps1YbusPcapv8kWirCZdgFU/RRUeyWhvs=; b=DxULorAR9zmm1vkoOjhx 80kitrZmz78al9rvwt/nxBvsHZ5Mj+PbdeDG91rt/f1ROtOCpSeYXBybjKQ4JP/eJqd2QY3uNwJHG BIwtuKNxIj2sLAsJOf8dxoQd0DC2oS2pQADZrULiW9FkJoHqotTH8V4JQop9NIPmM2y0Pj085kb5Y 5DsZarbMLlUPjc7YxoZtdf7a/ZahszxMF5DoV39toj0JssJiOZW1dE+UElrfzfJ+wh75LCkHtEMpZ KU9BgEQGEyGW07A85tdbqRMZoQ8SuJQoBSh+x+d7x8ZIwfDbkFkzgetRXekrVpMaKQ/CRVNBAxEXC oQdAq/kqEn2ypA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:63276 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrRs4-0005y4-Oi for 55398-done@debbugs.gnu.org; Wed, 18 May 2022 18:10:20 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: 55398-done@debbugs.gnu.org Subject: Re: bug#55398: [PATCH 0/3] Improve store caching; improve 'map/accumulate-builds' performance References: <20220513145947.11951-1-ludo@gnu.org> Date: Thu, 19 May 2022 00:10:18 +0200 In-Reply-To: <20220513145947.11951-1-ludo@gnu.org> ("Ludovic =?utf-8?Q?Cou?= =?utf-8?Q?rt=C3=A8s=22's?= message of "Fri, 13 May 2022 16:59:47 +0200") Message-ID: <875ym21ohh.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 55398-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Ludovic Court=C3=A8s skribis: > store: 'mcached' users can specify a cache ID. > packages: Use separate package/graft cache. > store: Use a decaying cutoff in 'map/accumulate-builds'. Pushed as 2f170893719e6e9fc8e19cc5f0568e20a95d92b4. Ludo=E2=80=99. ------------=_1652911861-24194-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 13 May 2022 14:59:58 +0000 Received: from localhost ([127.0.0.1]:44519 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWlp-00083N-My for submit@debbugs.gnu.org; Fri, 13 May 2022 10:59:57 -0400 Received: from lists.gnu.org ([209.51.188.17]:47606) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npWln-00083F-Vr for submit@debbugs.gnu.org; Fri, 13 May 2022 10:59:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWln-0000Tb-Ns for guix-patches@gnu.org; Fri, 13 May 2022 10:59:55 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npWln-0000NM-A2; Fri, 13 May 2022 10:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=sVpWpPSPLiNNg1U6tvP6nEFMs20+s4hKr6O/98nhAco=; b=VEKMDgfpW6Y0P7 fwpTaIzrPK+kMWMsSvWaaCJzx1qtE8bG5KCbYJBqTo50//5GQhzP6Sg37VrLsMDl7u9LdEN4qqwpn 4F6JdlpV4BElZN9fVL76wlbNOy1MlTpj5rZ02ShapwG3vNOav/12h9GD6bvcIoIKb9Xb4NvQfKEcD LF/qK2adkCSL1GoyxYpgo/YlefvCGe08Rh5dTBMSNlbE5DsXNZaJidZLX7xEXsVTnGnDZKTjiuNQT W2PuKEQvGSehs7/Lcx/fMUrMWx2sNCMMJ8hg8i1zwBO4OeASAJnyDTgyLBZtLElkxRq+uaJP7EJnu c0A6xTtMgE3V9VvL4V9A==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=44954 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npWlm-0008OV-6b; Fri, 13 May 2022 10:59:54 -0400 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= To: guix-patches@gnu.org Subject: [PATCH 0/3] Improve store caching; improve 'map/accumulate-builds' performance Date: Fri, 13 May 2022 16:59:47 +0200 Message-Id: <20220513145947.11951-1-ludo@gnu.org> X-Mailer: git-send-email 2.36.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit Cc: =?UTF-8?q?Ludovic=20Court=C3=A8s?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello! The first patch improves cache handling, providing a generic way to trace caches. The second patch adds a separate package/graft cache, as was previously suggested in a comment. The cache hit rate can be seen by setting GUIX_PROFILING: --8<---------------cut here---------------start------------->8--- $ time GUIX_PROFILING=package-graft-cache ./pre-inst-env guix home build -v1 -n ~/src/configuration/home-config.scm 28.5 MB would be downloaded Package Graft Cache: fresh caches: 1 lookups: 794 hits: 784 (98.7%) cache size: 10 entries real 0m7.953s user 0m9.091s sys 0m0.291s --8<---------------cut here---------------end--------------->8--- The last patch improves performance in the presence of grafts by trimming exploration of the call tree in ‘map/accumulate-builds’. This is very much a heuristic, but it does help significantly for ‘guix system’, ‘guix home’, or ‘guix package’ with many packages. Thoughts? Ludo’. Ludovic Courtès (3): store: 'mcached' users can specify a cache ID. packages: Use separate package/graft cache. store: Use a decaying cutoff in 'map/accumulate-builds'. guix/packages.scm | 12 ++++-- guix/store.scm | 104 +++++++++++++++++++++++++++++++++------------- 2 files changed, 84 insertions(+), 32 deletions(-) base-commit: 0b4300d4fd8c972f0cb9d6751fc824b9a065b780 -- 2.36.0 ------------=_1652911861-24194-1--