Gentoo Archives: gentoo-dev

From: Joshua Kinard <kumba@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] proposal: use only one hash function in manifest files
Date: Mon, 11 Apr 2022 23:14:17
Message-Id: f71dcd26-93e4-55f0-8195-91e975b9efb1@gentoo.org
In Reply to: Re: [gentoo-dev] proposal: use only one hash function in manifest files by "Jason A. Donenfeld"
1 On 4/5/2022 17:49, Jason A. Donenfeld wrote:
2 > Hi Matt,
3 >
4 > On Tue, Apr 5, 2022 at 10:38 PM Matt Turner <mattst88@g.o> wrote:
5 >>
6 >> On Tue, Apr 5, 2022 at 12:30 PM Jason A. Donenfeld <zx2c4@g.o> wrote:
7 >>> By the way, we're not currently _checking_ two hash functions during
8 >>> src_prepare(), are we?
9 >>
10 >> I don't know, but the hash-checking is definitely checked before src_prepare().
11 >
12 > Er, during the builtin fetch phase. Anyway, you know what I meant. :)
13 >
14 > Anyway, looking at the portage source code, to answer my own question,
15 > it looks like the file is actually being read twice and both hashes
16 > computed. I would have at least expected an optimization like:
17 >
18 > hash1_init(&hash1);
19 > hash2_init(&hash2);
20 > for chunks in file:
21 > hash1_update(&hash1, chunk);
22 > hash2_update(&hash2, chunk);
23 > hash1_final(&hash1, out1);
24 > hash2_final(&hash2, out2);
25 >
26 > But actually what's happening is the even less efficient:
27 >
28 > hash1_init(&hash1);
29 > for chunks in file:
30 > hash1_update(&hash1, chunk);
31 > hash1_final(&hash1, out1);
32 > hash2_init(&hash2);
33 > for chunks in file:
34 > hash2_update(&hash2, chunk);
35 > hash1_final(&hash2, out2);
36 >
37 > So the file winds up being open and read twice. For huge tarballs like
38 > chromium or libreoffice...
39 >
40 > But either way you do it - the missed optimization above or the
41 > unoptimized reality below - there's still twice as much work being
42 > done. This is all unless I've misread the source code, which is
43 > possible, so if somebody knows this code well and I'm wrong here,
44 > please do speak up.
45
46 Not to go off-topic, but where in Portage's source is this logic at? It
47 seems like an easy fix for a slightly more efficient Portage.
48
49 --
50 Joshua Kinard
51 Gentoo/MIPS
52 kumba@g.o
53 rsa6144/5C63F4E3F5C6C943 2015-04-27
54 177C 1972 1FB8 F254 BAD0 3E72 5C63 F4E3 F5C6 C943
55
56 "The past tempts us, the present confuses us, the future frightens us. And
57 our lives slip away, moment by moment, lost in that vast, terrible in-between."
58
59 --Emperor Turhan, Centauri Republic

Replies