From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 0F4FHIHmTWfpIgEAe85BDQ:P1 (envelope-from ) for ; Mon, 02 Dec 2024 16:55:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 0F4FHIHmTWfpIgEAe85BDQ (envelope-from ) for ; Mon, 02 Dec 2024 17:55:29 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=Q0XsTpXH; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=OBmfmDuQ; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1733158529; a=rsa-sha256; cv=none; b=YHQnTwvHE+8jGnYVmDhBiPy/nHEqVA/cQkkc1vZ2oGDk4K+QNzIIVnc4MBpAvOoZtSG49b rT1A3lam61zNis+KayhItcmBnIxMjYqJwUaM6or+rCMrbe2PWVgbdGWWtmYx3OL+9X1ZKN 2He/AFSwERfHc/MJYJuC8EK8nTyWkXZJWqN0M5gQfSliACjd6So0ptBbgGyGA/1pLIsfMx JmKVpgzwaaR+/5LlNX4cTY/uXi0eutCv9HsD6xjJ6Cpn7DyedSzwcX4e+2kIuGQDWdppFa z9rhfI+6BKbxCiBz0Ng+zXfJs3/y3alTb0YKXvnQuBuzbYTh2AeunPra9M7cQg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=Q0XsTpXH; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=OBmfmDuQ; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1733158529; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=rucvIXxZb70NbuOfSW/40lmBSTo34tbHlGOz0LCeoaY=; b=fqH7pglNaeTXPn7V0ljvF4SWCXo0PFAH0rrnWDMY+tE7QLCVGfkoHxCnXEthXIjlE0BQyO B9epzeV5Cxn1eAV1RCvmcv1huEjOsdTe8JB0IoK/0iyji4Pl13uZE7uBK/bmeCtfprFtbS 2C4bO3njVBKyfr19v69NqfLo9G60IVzeOzMqE5+OwWAPUqBT6xLAME7RQt0A5bZDg0NaMS wB81djX/yKlWrtViEhf1vuDTyPlapNzDOnIp1wKD7GMy6ZyyJPhYuoAmyU/32gh6XOFy+o 033NdeRN6WvtXPYSn1WmJ/0c5xQODhmgAkqy9KHTlHU1z/oeER09tvCeAnNZYg== 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 583F67AF5F for ; Mon, 02 Dec 2024 17:55:29 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tI9hT-0003tD-JZ; Mon, 02 Dec 2024 11:55:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tI9hP-0003lK-O5 for guix-patches@gnu.org; Mon, 02 Dec 2024 11:55:04 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tI9hP-0007ln-ET for guix-patches@gnu.org; Mon, 02 Dec 2024 11:55:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=rucvIXxZb70NbuOfSW/40lmBSTo34tbHlGOz0LCeoaY=; b=Q0XsTpXHVPBGgEJaVfM+8+MfGzGHLBLcOHSDryCAPfkHzxPr/9MH25IiiCddhdw1DtrVpAypdElBpHCMajbG/q8w5hCIf+dqAYyE6neU1YDpiLEMKRhDhoR6yPCOmMX2dgPA/wRWoLEKIwdU28xVYSnvz85a+iuTWDfTq59B5hPuqxxRT3SNtboWlTUY74s8vzzbSYVMK5YEBCl7L2/LDtuepCtLILrfh37qJTY+X0ri2MIMa7P8jALqiYehyV7d1R4OV3sVKgIpv2i21EBUYGxQay9it6w0X3/clLVNMSStRFAMKuyngljnPpFnQbK0RBQmWLnOoeNFIS/qwppSOw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tI9hP-00035z-7d for guix-patches@gnu.org; Mon, 02 Dec 2024 11:55:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74654] [PATCH 2/5] packages: Optimize =?UTF-8?Q?=E2=80=98all-packages=E2=80=99.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 02 Dec 2024 16:55:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74654 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74654@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 74654-submit@debbugs.gnu.org id=B74654.173315845411764 (code B ref 74654); Mon, 02 Dec 2024 16:55:03 +0000 Received: (at 74654) by debbugs.gnu.org; 2 Dec 2024 16:54:14 +0000 Received: from localhost ([127.0.0.1]:56354 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tI9gZ-00033Q-3w for submit@debbugs.gnu.org; Mon, 02 Dec 2024 11:54:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49914) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tI9gW-00032n-R6 for 74654@debbugs.gnu.org; Mon, 02 Dec 2024 11:54:09 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tI9gP-0007MG-E5; Mon, 02 Dec 2024 11:54:02 -0500 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=rucvIXxZb70NbuOfSW/40lmBSTo34tbHlGOz0LCeoaY=; b=OBmfmDuQgJV3+3cf7ccR +pe2Z7iTDrUH3hoXHsYT1wx2hrHbNOQGZTVDCKsn8NP/j9Ut6PLNdCaylneFtIbuV2YDWCTC/WK6l 3KGC5Rrq0HawiE840EWi20fI5YvRO557TuUpVg5JKD3IVJZnkiO9zA8dGxno0lnhcpQtBJresZoRI GukXjH+YVU1Qnoy2F0OB/3DCl2tivCvC4CK3T3w7S8suooFliv5d1cnB/7gXuKeqJzkLYQPfNYPaz 9aJQWGg3qAxBGdESsh7Tv6dzY0QgTKSMD20uPhHl2sHdBAtDewESFufowWN7+uSMtx7cBCPg5WX/l IOwgCoWT3PxyyQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 2 Dec 2024 17:53:27 +0100 Message-ID: <642880c208f4445f1d63dba5618a315671d558e2.1733158049.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 583F67AF5F X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -2.22 X-Spam-Score: -2.22 X-TUID: LxiLS7lawfcR On my laptop, wall-clock time for (all-packages) goes from 27s to 1s. * gnu/packages.scm (all-packages): Use a hash table to remember visited packages instead of calling ‘delete-duplicates’ on the final list. Change-Id: I4aae804656b56ef2095993e91f0572a5891f419f --- gnu/packages.scm | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/gnu/packages.scm b/gnu/packages.scm index 1af3b8d440..bdd5d21940 100644 --- a/gnu/packages.scm +++ b/gnu/packages.scm @@ -258,18 +258,26 @@ (define all-packages (mlambda () "Return the list of all public packages, including replacements and hidden packages, excluding superseded packages." - (delete-duplicates - (fold-packages (lambda (package result) - (match (package-replacement package) - ((? package? replacement) - (cons* replacement package result)) - (#f - (cons package result)))) - '() + ;; Note: 'fold-packages' never traverses the same package twice but + ;; replacements break that (they may or may not be visible to + ;; 'fold-packages'), hence this hash table to track visited packages. + (define visited (make-hash-table)) - ;; Dismiss deprecated packages but keep hidden packages. - #:select? (negate package-superseded)) - eq?))) + (fold-packages (lambda (package result) + (if (hashq-ref visited package) + result + (begin + (hashq-set! visited package #t) + (match (package-replacement package) + ((? package? replacement) + (hashq-set! visited replacement #t) + (cons* replacement package result)) + (#f + (cons package result)))))) + '() + + ;; Dismiss deprecated packages but keep hidden packages. + #:select? (negate package-superseded)))) (define %package-cache-file ;; Location of the package cache. -- 2.46.0