git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] pack-objects: break out of want_object loop early
Date: Tue, 26 Jul 2016 16:48:51 -0400	[thread overview]
Message-ID: <20160726204851.GA22353@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqshuwyw14.fsf@gitster.mtv.corp.google.com>

On Tue, Jul 26, 2016 at 01:38:47PM -0700, Junio C Hamano wrote:

> Jeff King <peff@peff.net> writes:
> 
> >> I do not mind too much about having to check two bools twice.  But
> >> given that the reason why I was confused was because I didn't see
> >> why we need to pass the two "return 0" conditions at least once
> >> before we decide that we do not need the "return 0" thing at all,
> >> and started constructing a case where this might break by writing
> >> "Suppose you have two packs, one remote and one local in packed_git
> >> list in this order, and ..." before I realized that the new "early
> >> break" can be hoisted up like the above, I definitely feel that "we
> >> found one, and we aren't conditionally pretending that this thing
> >> does not need to be packed at all, so return early and say we want
> >> to pack it" is easier to understand before the two existing "if"
> >> statements.
> >
> > Ah, right. Now you had me second-guessing for a moment that there might
> > be a bad case in hoisting it up where we would want to return 0 but
> > would break out early to the "return 1".
> >
> > But it cannot be the case, because the break is mutually exclusive with
> > the two conditions.
> 
> Here is what I amended looks like (with s/local/non-local/ in the
> log message).

Thanks, I was actually just preparing a very similar patch (to move the
condition and to add a comment, since clearly it is tricky).

I got side-tracked by adding a t/perf test to show off the improvement.
It's rather tricky to get right and takes a long time to run. I _think_
I have it now, but am waiting for results. :)

> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
> index a2f8cfd..a46bf5b 100644
> --- a/builtin/pack-objects.c
> +++ b/builtin/pack-objects.c
> @@ -977,6 +977,21 @@ static int want_object_in_pack(const unsigned char *sha1,
>  				return 1;
>  			if (incremental)
>  				return 0;
> +
> +			/*
> +			 * When asked to do --local (do not include an
> +			 * object that appears in a pack we borrow
> +			 * from elsewhere) or --honor-pack-keep (do not
> +			 * include an object that appears in a pack marked
> +			 * with .keep), we need to make sure no copy of this
> +			 * object come from in _any_ pack that causes us to
> +			 * omit it, and need to complete this loop.  When
> +			 * neither option is in effect, we know the object
> +			 * we just found is going to be packed, so break
> +			 * out of the loop to return 1 now.
> +			 */
> +			if (!ignore_packed_keep && !local)
> +				break;

This looks great. Given the explanation in the comment, it might be more
clear to switch the break to "return 1", but I could go either way.

-Peff

  reply	other threads:[~2016-07-26 20:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-25 18:49 [PATCH 0/2] speed up "Counting objects" when there are many packs Jeff King
2016-07-25 18:50 ` [PATCH 1/2] pack-objects: break out of want_object loop early Jeff King
2016-07-25 19:56   ` Junio C Hamano
2016-07-25 21:41     ` Jeff King
2016-07-25 21:52       ` Junio C Hamano
2016-07-25 22:14         ` Jeff King
2016-07-26 20:38           ` Junio C Hamano
2016-07-26 20:48             ` Jeff King [this message]
2016-07-26 21:38               ` Junio C Hamano
2016-07-27 21:13                 ` Jeff King
2016-07-27 21:28                   ` Junio C Hamano
2016-07-27 22:04                     ` Jeff King
2016-07-25 18:50 ` [PATCH 2/2] pack-objects: compute local/ignore_pack_keep early Jeff King

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: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20160726204851.GA22353@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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://80x24.org/mirrors/git.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).