From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: friel@openai.com, git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH v2] pack-objects: trace pack bytes written
Date: Thu, 20 Aug 2026 11:13:16 +0200 [thread overview]
Message-ID: <aobFLJuiuM1EuNpv@pks.im> (raw)
In-Reply-To: <20260820082102.GA2973952@coredump.intra.peff.net>
On Thu, Aug 20, 2026 at 04:21:02AM -0400, Jeff King wrote:
> On Thu, Aug 20, 2026 at 07:41:33AM +0200, Patrick Steinhardt wrote:
> > On Wed, Aug 19, 2026 at 04:28:10PM -0700, friel@openai.com wrote:
> > > diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> > > index 1ec5b6f206..252530172c 100644
> > > --- a/builtin/pack-objects.c
> > > +++ b/builtin/pack-objects.c
> > > @@ -1389,6 +1390,8 @@ static void write_pack_file(void)
> > > display_progress(progress_state, written);
> > > }
> > >
> > > + bytes_written += hashfile_total(f) +
> > > + the_repository->hash_algo->rawsz;
> > > if (pack_to_stdout) {
> > > /*
> > > * We never fsync when writing to stdout since we may
> >
> > I guess the addition here accounts for the trailing hash written by the
> > hashfile. If so, shouldn't we also use the algortihm that the hashfile
> > uses in the first place via `f->algop->rawsz`?
>
> Perhaps, though that is used to write the hash (via CSUM_HASH_IN_STREAM)
> only in two of the conditional blocks. In the third we finalize the
> hashfile and then use fixup_pack_header_footer(), passing the_hash_algo
> directly (not even the_repository->hash_algo, though of course they mean
> the same thing).
>
> It all works out, of course, because we created the hashfile struct
> earlier using the_repository->hash_algo. So I think this is mostly
> academic in the first place, but your suggestion harmonizes two of the
> conditional blocks while creating disagreement with the third.
>
> I think something like this would "fix" it by consistently using the
> hashfile's algo in all three blocks:
>
> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index 4a5fcbe5f5..0fdff72f41 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -1413,9 +1413,9 @@ static void write_pack_file(void)
> * If we wrote the wrong number of entries in the
> * header, rewrite it like in fast-import.
> */
> -
> + const struct git_hash_algo *algo = f->algop;
> int fd = finalize_hashfile(f, hash, FSYNC_COMPONENT_PACK, 0);
> - fixup_pack_header_footer(the_hash_algo, fd, hash,
> + fixup_pack_header_footer(algo, fd, hash,
> pack_tmp_name, nr_written,
> hash, offset);
> close(fd);
>
>
> But there's a subtle yet interesting difference here! f->algop won't
> necessarily be the same pointer as the_hash_algo. If we compiled with an
> unsafe variant, that will be used for hashfiles. If we're just looking
> at rawsz that's OK; the two variants should be identical (other than
> performance and collision detection), so taking rawsz from either is
> fine.
>
> But fixup_pack_header_footer() actually recomputes the hash (as it must
> if we tweak the header). Right now it does it using the "normal"
> variant, but we should be able to use the unsafe one (which my diff
> snippet above would start to do).
Yeah, I agree that switching over to the unsafe algortihm is sensible.
Being able to speed up hashing of packfiles was one of the prime
motivations of introducing the unsafe variants in the first place, so
the fact that we still use the safe variant here feels like a plain
oversight to me.
> Of course this whole thing is absurdly pessimal in the first place. If
> we are just going to throw out the hashfile's checksum, then why bother
> computing it in the first place? Because we don't trust a disk write at
> all, and actually verify the original hash computation as we read the
> bytes back in! So we'll actually sha1 the written packfile three times.
> Yikes. I wonder if it's really worth being so paranoid. But that is how
> it has always been.
That's... awful. Honestly, if we cannot trust what we're writing to disk
we're going to be kind of screwed anyway. We don't re-verify loose
objects, refs or whatever other data structures we write to disk either.
So doing this thrice here feels wrong.
> Anyway, that is a bit of a tangent from the patch in question. I think
> either spelling is OK for the purposes of this patch. If somebody wants
> to pursue harmonizing the paths (and maybe even doing some timings to
> see if switching to the unsafe variant is noticeable here, and what the
> total cost of this triple-write approach is), that can happen
> separately.
I agree that this is definitely out of scope of this patch series.
Patrick
next prev parent reply other threads:[~2026-08-20 9:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 23:39 [PATCH] pack-objects: trace pack bytes written friel
2026-08-18 1:08 ` Junio C Hamano
2026-08-19 23:28 ` [PATCH v2] " friel
2026-08-20 5:41 ` Patrick Steinhardt
2026-08-20 8:21 ` Jeff King
2026-08-20 9:13 ` Patrick Steinhardt [this message]
2026-08-20 15:35 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aobFLJuiuM1EuNpv@pks.im \
--to=ps@pks.im \
--cc=friel@openai.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.