From patchwork Thu Aug 3 08:46:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Baines X-Patchwork-Id: 52464 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 676EA27BBE9; Thu, 3 Aug 2023 09:47:32 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2217927BBE2 for ; Thu, 3 Aug 2023 09:47:32 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRTzH-0005f9-Sn; Thu, 03 Aug 2023 04:47:15 -0400 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 1qRTz7-0005YQ-2d for guix-patches@gnu.org; Thu, 03 Aug 2023 04:47:05 -0400 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 1qRTz6-0003rS-Qc; Thu, 03 Aug 2023 04:47:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qRTz4-0002zJ-0V; Thu, 03 Aug 2023 04:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65033] [PATCH] guix: read-derivation-from-file: Use less open files. Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: mail@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 03 Aug 2023 08:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65033 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65033@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.169105238811426 (code B ref -1); Thu, 03 Aug 2023 08:47:01 +0000 Received: (at submit) by debbugs.gnu.org; 3 Aug 2023 08:46:28 +0000 Received: from localhost ([127.0.0.1]:50813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRTyV-0002yE-Nc for submit@debbugs.gnu.org; Thu, 03 Aug 2023 04:46:28 -0400 Received: from lists.gnu.org ([2001:470:142::17]:50830) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qRTyU-0002y0-16 for submit@debbugs.gnu.org; Thu, 03 Aug 2023 04:46:26 -0400 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 1qRTyO-0005U1-Qn for guix-patches@gnu.org; Thu, 03 Aug 2023 04:46:20 -0400 Received: from mira.cbaines.net ([2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRTyM-0003Kl-GP for guix-patches@gnu.org; Thu, 03 Aug 2023 04:46:19 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:3a91:a0a4:ecee:f157]) by mira.cbaines.net (Postfix) with ESMTPSA id 1BA0527BBE2 for ; Thu, 3 Aug 2023 09:46:14 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id 68e668e0 for ; Thu, 3 Aug 2023 08:46:13 +0000 (UTC) From: Christopher Baines Date: Thu, 3 Aug 2023 09:46:12 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a01:7e00:e000:2f8:fd4d:b5c7:13fb:3d27; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches The Guix derivation graph isn't that deep, so I don't think this generally opens lots of files, but I think it's still unnecessary to keep more files than needed open. * guix/derivations.scm (read-derivation-from-file): Read each derivation to a string, which is passed as a port to read-derivation. --- guix/derivations.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) base-commit: fe3e05d8b3dbb255179d3f85aca870e6085bb71a prerequisite-patch-id: 2322b3b5ce79bdaa763075cdbb96e760168d4c63 diff --git a/guix/derivations.scm b/guix/derivations.scm index 9fec7f4f0b..2154bd76f6 100644 --- a/guix/derivations.scm +++ b/guix/derivations.scm @@ -31,6 +31,7 @@ (define-module (guix derivations) #:use-module (ice-9 match) #:use-module (ice-9 rdelim) #:use-module (ice-9 vlist) + #:use-module (ice-9 textual-ports) #:use-module (guix store) #:use-module (guix utils) #:use-module (guix base16) @@ -556,7 +557,14 @@ (define (read-derivation-from-file file) ;; and because the same argument is read more than 15 times on average ;; during something like (package-derivation s gdb). (or (and file (hash-ref %derivation-cache file)) - (let ((drv (call-with-input-file file read-derivation))) + (let ((drv + ;; read-derivation can call read-derivation-from-file, so to + ;; avoid having multiple open files when reading a derivation + ;; with inputs, read it in to a string first. + (call-with-input-string + (call-with-input-file file + get-string-all) + read-derivation))) (hash-set! %derivation-cache file drv) drv)))