From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6Kx6IvUAEGAmDgAA0tVLHw (envelope-from ) for ; Tue, 26 Jan 2021 11:45:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gKNKHvUAEGA7VQAAbx9fmQ (envelope-from ) for ; Tue, 26 Jan 2021 11:45:57 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 0360D9403EB for ; Tue, 26 Jan 2021 11:45:56 +0000 (UTC) Received: from localhost ([::1]:50268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4MnD-000559-PV for larch@yhetil.org; Tue, 26 Jan 2021 06:45:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:38210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l4MYp-0008VJ-94 for guix-patches@gnu.org; Tue, 26 Jan 2021 06:31:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:57575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l4MYn-0004gR-TX for guix-patches@gnu.org; Tue, 26 Jan 2021 06:31:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l4MYn-0005Z2-Pf for guix-patches@gnu.org; Tue, 26 Jan 2021 06:31:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#46100] [PATCH 0/4] Memoize inferior package access. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 26 Jan 2021 11:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46100 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Ricardo Wurmus Received: via spool by 46100-submit@debbugs.gnu.org id=B46100.161166064921358 (code B ref 46100); Tue, 26 Jan 2021 11:31:01 +0000 Received: (at 46100) by debbugs.gnu.org; 26 Jan 2021 11:30:49 +0000 Received: from localhost ([127.0.0.1]:40887 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l4MYa-0005YP-Kf for submit@debbugs.gnu.org; Tue, 26 Jan 2021 06:30:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48464) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l4MYW-0005Y9-Mj for 46100@debbugs.gnu.org; Tue, 26 Jan 2021 06:30:46 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46161) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l4MYQ-0004Tq-9u; Tue, 26 Jan 2021 06:30:38 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=35696 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l4MYP-0004IL-0E; Tue, 26 Jan 2021 06:30:37 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20210125133738.15609-1-rekado@elephly.net> <20210125133738.15609-2-rekado@elephly.net> <878s8g0yln.fsf_-_@gnu.org> Date: Tue, 26 Jan 2021 12:30:34 +0100 In-Reply-To: <878s8g0yln.fsf_-_@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Tue, 26 Jan 2021 11:41:24 +0100") Message-ID: <874kj40wbp.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 46100@debbugs.gnu.org Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.35 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 0360D9403EB X-Spam-Score: -1.35 X-Migadu-Scanner: scn1.migadu.com X-TUID: AsgIN9VWZmPI --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s skribis: > There=E2=80=99s a catch here: OUTPUT should be taken into account. > > Also it=E2=80=99s better to use eq?-ness but=E2=80=A6 I realized > =E2=80=98inferior-package-inputs=E2=80=99 & co. do not preserve eq?-ness. I think I went overboard here: given that is a simple flat record type, using =E2=80=98equal?=E2=80=99/=E2=80=98hash-ref=E2=80=99= is reasonable and that way we avoid the troubles of building an ID-to-package table. All in all it=E2=80=99s slightly more efficient. WDYT? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/guix/inferior.scm b/guix/inferior.scm index 2fe91beaab..d813b3b918 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -642,29 +642,41 @@ failing when GUIX is too old and lacks the 'guix repl' command." (define* (inferior-package->manifest-entry package #:optional (output "out") - #:key (parent (delay #f)) - (properties '())) + #:key (properties '())) "Return a manifest entry for the OUTPUT of package PACKAGE." ;; For each dependency, keep a promise pointing to its "parent" entry. - (letrec* ((deps (map (match-lambda - ((label package) - (inferior-package->manifest-entry package - #:parent (delay entry))) - ((label package output) - (inferior-package->manifest-entry package output - #:parent (delay entry)))) - (inferior-package-propagated-inputs package))) - (entry (manifest-entry - (name (inferior-package-name package)) - (version (inferior-package-version package)) - (output output) - (item package) - (dependencies (delete-duplicates deps)) - (search-paths - (inferior-package-transitive-native-search-paths package)) - (parent parent) - (properties properties)))) - entry)) + (define cache + (make-hash-table)) + + (define-syntax-rule (memoized package output exp) + (let ((compute (lambda () exp)) + (key (cons package output))) + (or (hash-ref cache key) + (let ((result (compute))) + (hash-set! cache key result) + result)))) + + (let loop ((package package) + (output output) + (parent (delay #f))) + (memoized package output + (letrec* ((deps (map (match-lambda + ((label package) + (loop package "out" (delay entry))) + ((label package output) + (loop package output (delay entry)))) + (inferior-package-propagated-inputs package))) + (entry (manifest-entry + (name (inferior-package-name package)) + (version (inferior-package-version package)) + (output output) + (item package) + (dependencies (delete-duplicates deps)) + (search-paths + (inferior-package-transitive-native-search-paths package)) + (parent parent) + (properties properties)))) + entry)))) ;;; @@ -750,3 +762,7 @@ This is a convenience procedure that people may use in manifests passed to #:cache-directory cache-directory #:ttl ttl))) (open-inferior cached)) + +;;; Local Variables: +;;; eval: (put 'memoized 'scheme-indent-function 1) +;;; End: --=-=-=--