From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 09 10:51:17 2021 Received: (at 50384) by debbugs.gnu.org; 9 Sep 2021 14:51:17 +0000 Received: from localhost ([127.0.0.1]:35974 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOLOX-0000MV-0L for submit@debbugs.gnu.org; Thu, 09 Sep 2021 10:51:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50022) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mOLOV-0000MH-5n for 50384@debbugs.gnu.org; Thu, 09 Sep 2021 10:51:15 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34170) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mOLOP-0001GS-9y; Thu, 09 Sep 2021 10:51:09 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=47216 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mOLOP-0003Xv-0d; Thu, 09 Sep 2021 10:51:09 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Maxime Devos Subject: Re: bug#50384: [PATCH] Optimise search-patch (reducing I/O) References: <8900fa8c8eef7f72fc97adc2408be26c88de7803.camel@telenet.be> <87tuj0xaja.fsf@gnu.org> <0ec7f0270fcccec730808f9210f074cd5339961f.camel@telenet.be> Date: Thu, 09 Sep 2021 16:51:07 +0200 In-Reply-To: <0ec7f0270fcccec730808f9210f074cd5339961f.camel@telenet.be> (Maxime Devos's message of "Sun, 05 Sep 2021 21:48:22 +0200") Message-ID: <87ee9xerac.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 50384 Cc: 50384@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hello, Maxime Devos skribis: >> To address this, =E2=80=98local-file=E2=80=99 could store the inode/mtim= e + computed >> store file name (rather than the SHA256). =E2=80=98local-file-compiler= =E2=80=99 would >> check whether the actual file has matching inode/mtime before returning >> the computed store file name. Problem is that inode/mtime are >> guaranteed to differ once you=E2=80=99ve run =E2=80=9Cmake install=E2=80= =9D. :-/ > > An additional problem is that 'local-file-compiler' would have to 'stat' > the file even if it is already in the store, undoing the (fairly limited?) > performance gains of this patch series. > > The dependency tracking avoids this. OK. >> Intuitively, I=E2=80=99d have imagined a cache populated at run time; it= would >> map, say, file name/inode/mtime to a store file name. =E2=80=98add-to-s= tore=E2=80=99 >> (or some wrapper above it) would check the cache and return the store >> file name directly, unless =E2=80=98valid-path?=E2=80=99 says it no long= er exists. >> Downside is that this would be a per-user cache and you=E2=80=99d still = pay the >> cost until it=E2=80=99s warm. Advantage is that you could easily tell w= hether >> it=E2=80=99s stale. >>=20 >> Thoughts? > > Intuitively, I'd have imagined doing as much as possible at compilation t= ime. Of course, but it=E2=80=99s important for the caching model to match =E2=80= =9Creality=E2=80=9D, which is that patch files live independently of the source files that refer to them. I=E2=80=99d all be fine if =E2=80=98local-file=E2=80=99 were to inline file= contents at macro-expansion time, because then we could be sure the hash and contents match (but I=E2=80=99m not saying we should do this=E2=80=A6). What we could do is have a boolean saying whether the cached value is authoritative, similar to what=E2=80=99s in (gnu packages). That way, when using ./pre-inst-env or passing a -L flag or setting GUIX_PACKAGE_PATH, the cached value would not be authoritative; we=E2=80=99d be safe, without needing ad hoc dependency tracking. Thoughts? [...] > Because fixed-output-path is now called more often, I've added a patch > optimising (guix base32). [...] > From e5dc46800597023dfc1c9d53cc6e0db2f3999022 Mon Sep 17 00:00:00 2001 > From: Maxime Devos > Date: Sat, 4 Sep 2021 15:35:51 +0200 > Subject: [PATCH v2 3/9] gexp: Allow computing the hash of the local file = in > advance. > > The new field is currently unused. The following patches will > populate and use the field to reduce the time-to-derivation > when the file is already interned in the store. > > * guix/gexp.scm > (): Add sha256 field. > (%local-file): Add sha256 argument for populating the field. > (local-file-compiler): Adjust 'match' expression. [...] > +;; repeated 'stat' calls. Allow computing the hash of the file in advan= ce, > +;; to avoid having to send the file to the daemon when it is already int= erned > +;; in the store. > (define-record-type > - (%%local-file file absolute name recursive? select?) > + (%%local-file file absolute name sha256 recursive? select?) > local-file? > (file local-file-file) ;string > (absolute %local-file-absolute-file-name) ;promise string > (name local-file-name) ;string > + (sha256 local-file-sha256) ;sha256 bytevector | #f Could we store the result of =E2=80=98fixed-output-path=E2=80=99 rather tha= n the SHA256, while we=E2=80=99re at it? Again, care must be taken because it=E2=80=99s possible to set NIX_STORE_DI= R at run time, which may invalidate the pre-computed store file name. Can we make hash/file name computation a feature of =E2=80=98local-file=E2= =80=99 rather than one of =E2=80=98search-patch=E2=80=99 as in these patches? I=E2=80=99= d rather not provide a way to override this new field. There are cases where we cannot know the value of =E2=80=98recursive?=E2=80= =99 at expansion time, for instance if the user wrote: (local-file "foo.txt" #:recursive? r) In that case, we cannot compute the hash or file name. Thanks, Ludo=E2=80=99.