From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oC0kDj9e8mGulAAAgWs5BA (envelope-from ) for ; Thu, 27 Jan 2022 09:56:31 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id GLXMBj9e8mEiMQEAG6o9tA (envelope-from ) for ; Thu, 27 Jan 2022 09:56:31 +0100 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 BA23A2938F for ; Thu, 27 Jan 2022 09:56:30 +0100 (CET) Received: from localhost ([::1]:39290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nD0Zx-0004hL-V9 for larch@yhetil.org; Thu, 27 Jan 2022 03:56:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nD0Sn-0008AZ-Hd for bug-guix@gnu.org; Thu, 27 Jan 2022 03:49:08 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:33147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nD0Sl-0000vi-Lo for bug-guix@gnu.org; Thu, 27 Jan 2022 03:49:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nD0Sl-0007m1-Kr for bug-guix@gnu.org; Thu, 27 Jan 2022 03:49:03 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#48007: [PATCH 3/4] inferior: Inferior caches store connections. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Thu, 27 Jan 2022 08:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48007 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 48007@debbugs.gnu.org Received: via spool by 48007-submit@debbugs.gnu.org id=B48007.164327330929818 (code B ref 48007); Thu, 27 Jan 2022 08:49:03 +0000 Received: (at 48007) by debbugs.gnu.org; 27 Jan 2022 08:48:29 +0000 Received: from localhost ([127.0.0.1]:54280 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nD0SC-0007km-Rg for submit@debbugs.gnu.org; Thu, 27 Jan 2022 03:48:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33150) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nD0S5-0007jx-C7 for 48007@debbugs.gnu.org; Thu, 27 Jan 2022 03:48:22 -0500 Received: from [2001:470:142:3::e] (port=51732 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nD0S0-0000sT-3W; Thu, 27 Jan 2022 03:48:16 -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=WPijy0Tmt+Eb0k4WcLUzw/zNkq8zFUXPLJ8AhN9hpBI=; b=m+fkx0QKg41ZplmXmSGM VvS+ibRFx1RuknJiN8Q+m70R0mCv2WrsJY/fEGVrlFtE6Z60VGj+/uLMX/azWpjgYAzYQBo41prLz l4t6tH+lEsUxdk4lXlMi2p1+32AzUYa32DJqYHnEtApTHUg9+gpeJv0bxdIFPzABBMfCpb0DhDEoo RMFa2dMZ4mLPLokklP4HgXvh/pSixsRlfd7+OH3mPHoSqTzrI/kHyuWfL5OUSttCtWTOGP9FJBt2Y icJ+sUob5jc2OySQsOMhv3t/Emyzt+2D8YrVL5r/6BSaGCexz058xPflERUnECce5Er9GNbKl9zL9 Ir2L6etj6pnH0w==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:60148 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 1nD0Rw-0002sQ-Lr; Thu, 27 Jan 2022 03:48:15 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 27 Jan 2022 09:47:42 +0100 Message-Id: <20220127084743.27130-3-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220127084743.27130-1-ludo@gnu.org> References: <87r18ufcft.fsf@gnu.org> <20220127084743.27130-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643273790; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: 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=WPijy0Tmt+Eb0k4WcLUzw/zNkq8zFUXPLJ8AhN9hpBI=; b=QWaxLzdUHS6coXe/mmqsXCDeXwO3RvbiRj4ZWkvw8NRlXfP6x8z1AnQm3YTH+zsR7g1F6+ QYJYkYkGSWTjima5MXl5UhmotPVK3YEJ3eN8ZhGnZXxPj82v0GCwIJByfSGTq+9Uo5AeKF 2cSPff+MYb771FNv7xOjj2NNp/v7P9yk2g8bAboHdrl7KFjZLWBDN8BCE0jNAACmuVHvVf kADfK2oojQihHleSjQhSE3pQAA0ZjAAdqRcVpyPMpf6vZlQgaXal0SMzJKzdSUwJfL066y o60YMSnbt1dwEH0JU0XYYJTTODGcxwpSKyQtTsWTFqgzPuRj2+pq9mlsSx4uIw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643273790; a=rsa-sha256; cv=none; b=YpNnOeSjX8LnLjRvaYNE22lb0koQIsLIPF50PjcTdGK2ndppEjoVwXM5gxEzqLdS9Nietb FZ/xqovveQIMpNcXB5ER1a1HZSLZx2Mh9YaV3wlXOW49hKvUKc8VMzPbgDB3ugMoIWlUh5 FCUUzLig/mh1lJ1qdiRIw/hcXcgD9domHRvUi2mfGf1cr+706y6I7iJwapZv7J5FXjoy1w OSoNU7rKxyGIx9yQo166MiUs1v2iGBEa7l4l0b762a7wSUjFMx57yr/vvCTSUWdi1UAJyp XRumJWEU8KMGAtjIKAYz/nuiNITpywsNiD6fI6TDkGU0YMwN4w/cHP91jgdoKw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=m+fkx0QK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.33 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=m+fkx0QK; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "bug-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="bug-guix-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: BA23A2938F X-Spam-Score: -2.33 X-Migadu-Scanner: scn1.migadu.com X-TUID: 7jPZj/j6n5SK Fixes . Reported by Ricardo Wurmus . Previously, at each 'inferior-eval-with-store' call, the inferior would create a new object with empty caches. Consequently, when repeatedly calling 'inferior-package-derivation', we would not benefit from any caching and instead recompute all the derivations for every package. This patch fixes it by caching objects in the inferior. * guix/inferior.scm (port->inferior): Define '%store-table' in the inferior. (inferior-eval-with-store): Cache store connections in %STORE-TABLE. Remove now unneeded 'dynamic-wind' with 'close-port' call. --- guix/inferior.scm | 54 +++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/guix/inferior.scm b/guix/inferior.scm index 1c19527b8f..64dd1ce9b6 100644 --- a/guix/inferior.scm +++ b/guix/inferior.scm @@ -225,6 +225,8 @@ (define* (port->inferior pipe #:optional (close close-port)) (inferior-eval '(use-modules (srfi srfi-34)) result) (inferior-eval '(define %package-table (make-hash-table)) result) + (inferior-eval '(define %store-table (make-hash-table)) + result) result)) (_ #f))) @@ -617,7 +619,12 @@ (define (inferior-eval-with-store inferior store code) thus be the code of a one-argument procedure that accepts a store." (let* ((major (store-connection-major-version store)) (minor (store-connection-minor-version store)) - (proto (logior major minor))) + (proto (logior major minor)) + + ;; The address of STORE itself is not a good identifier because it + ;; keeps changing through the use of "functional caches". The + ;; address of its socket port makes more sense. + (store-id (object-address (store-connection-socket store)))) (ensure-store-bridge! inferior) (send-inferior-request `(let ((proc ,code) @@ -628,26 +635,31 @@ (define (inferior-eval-with-store inferior store code) store-protocol-error-message nix-protocol-error-message))) - ;; 'port->connection' appeared in June 2018 and we can hardly - ;; emulate it on older versions. Thus fall back to - ;; 'open-connection', at the risk of talking to the wrong daemon or - ;; having our build result reclaimed (XXX). - (let ((store (if (defined? 'port->connection) - (port->connection %bridge-socket #:version ,proto) - (open-connection)))) - (dynamic-wind - (const #t) - (lambda () - ;; Serialize '&store-protocol-error' conditions. The - ;; exception serialization mechanism that - ;; 'read-repl-response' expects is unsuitable for SRFI-35 - ;; error conditions, hence this special case. - (guard (c ((error? c) - `(store-protocol-error ,(error-message c)))) - `(result ,(proc store)))) - (lambda () - (unless (defined? 'port->connection) - (close-port store)))))) + ;; Cache connections to STORE-ID. This ensures that the caches within + ;; (in particular the object cache) are reused + ;; across calls to 'inferior-eval-with-store', which makes a + ;; significant different when it is called repeatedly. + (let ((store (or (hashv-ref %store-table ,store-id) + + ;; 'port->connection' appeared in June 2018 and we + ;; can hardly emulate it on older versions. Thus + ;; fall back to 'open-connection', at the risk of + ;; talking to the wrong daemon or having our build + ;; result reclaimed (XXX). + (let ((store (if (defined? 'port->connection) + (port->connection %bridge-socket + #:version ,proto) + (open-connection)))) + (hashv-set! %store-table ,store-id store) + store)))) + + ;; Serialize '&store-protocol-error' conditions. The + ;; exception serialization mechanism that + ;; 'read-repl-response' expects is unsuitable for SRFI-35 + ;; error conditions, hence this special case. + (guard (c ((error? c) + `(store-protocol-error ,(error-message c)))) + `(result ,(proc store))))) inferior) (proxy inferior store) -- 2.34.0