unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Ricardo Wurmus <rekado@elephly.net>
Cc: 48007@debbugs.gnu.org
Subject: bug#48007: computing derivations through inferior takes twice as long
Date: Wed, 26 Jan 2022 21:51:18 +0100	[thread overview]
Message-ID: <87r18ufcft.fsf@gnu.org> (raw)
In-Reply-To: <87wnsrpf25.fsf@elephly.net> (Ricardo Wurmus's message of "Sat, 24 Apr 2021 23:07:14 +0200")

[-- Attachment #1: Type: text/plain, Size: 1320 bytes --]

Hi!

Ricardo Wurmus <rekado@elephly.net> skribis:

> When INFERIOR is set to “y”, each package specification will be 
> looked up in the current Guix via an inferior.  For any other 
> values of INFERIOR the specifications are resolved with the 
> current Guix (the very same Guix) directly.
>
> Here are the timings:
>
> $ [env] export GUIX_PROFILING="object-cache 
> add-data-to-store-cache rpc"
> $ [env] time INFERIOR=n guix build -m manifest-test.scm -d
> /gnu/store/mwg47gbmi98bbrywk07y5l2h9p6d1hz5-bash-minimal-5.0.16.drv
> /gnu/store/kcjk6z128fa07pzp8irp6lbbyl3g16nr-r-corrplot-0.84.drv

[...]

> $ [env] time INFERIOR=y guix build -m manifest-test.scm -d

With the manifest you gave in this message, I get roughly these
wall-clock times as of 3993d33d1c0129b1ca6f0fd122fe2bbe48e4f093 for:

  guix build -m the-manifest.scm -n

  INFERIOR=n   4.1s
  INFERIOR=y  36.9s

With the patch below, it’s down to:

  INFERIOR=y   9.3s

The trick is to ensure the inferior maintains its object cache across
calls.  The patch needs to be cleaned up because it peeks into
internals, but we should be able to do something along these lines and
optimize a couple of other things.

If you can give it a spin on a more representative example, that’s
great!

Thanks,
Ludo’.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 1552 bytes --]

diff --git a/guix/inferior.scm b/guix/inferior.scm
index 572114f626..f6866d2083 100644
--- a/guix/inferior.scm
+++ b/guix/inferior.scm
@@ -188,6 +188,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 %previous-object-cache #f)
+                      result)
        result))
     (_
      #f)))
@@ -559,6 +561,10 @@ (define (inferior-eval-with-store inferior store code)
            (let ((store (if (defined? 'port->connection)
                             (port->connection socket #:version ,proto)
                             (open-connection))))
+             (when %previous-object-cache
+               (set-store-connection-cache! store (@@ (guix store) %object-cache-id)
+                                            %previous-object-cache))
+
              (dynamic-wind
                (const #t)
                (lambda ()
@@ -570,6 +576,9 @@ (define (inferior-eval-with-store inferior store code)
                             `(store-protocol-error ,(error-message c))))
                    `(result ,(proc store))))
                (lambda ()
+                 (set! %previous-object-cache
+                       (store-connection-cache store
+                                               (@@ (guix store) %object-cache-id)))
                  (close-connection store)
                  (close-port socket)))))
         inferior)

  reply	other threads:[~2022-01-26 20:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24 21:07 bug#48007: computing derivations through inferior takes twice as long Ricardo Wurmus
2022-01-26 20:51 ` Ludovic Courtès [this message]
2022-01-26 21:32   ` Ricardo Wurmus
2022-01-27  8:50     ` Ludovic Courtès
2022-01-27  9:56       ` Ricardo Wurmus
2022-01-27 13:33         ` Ludovic Courtès
2022-01-27  8:47   ` bug#48007: [PATCH 1/4] inferior: Create the store proxy listening socket only once Ludovic Courtès
2022-01-27  8:47     ` bug#48007: [PATCH 2/4] inferior: Keep the store bridge connected Ludovic Courtès
2022-02-18 11:30       ` bug#48007: computing derivations through inferior takes twice as long Ludovic Courtès
2022-01-27  8:47     ` bug#48007: [PATCH 3/4] inferior: Inferior caches store connections Ludovic Courtès
2022-01-27  8:47     ` bug#48007: [PATCH 4/4] inferior: Move initialization bits away from 'inferior-eval-with-store' Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r18ufcft.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=48007@debbugs.gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).