git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] pack-objects: break out of want_object loop early

From
Jeff King <peff@peff.net>
Date
Jul 25, 2016, 22:14 UTC
Message-ID
<20160725221411.GA14131@sigill.intra.peff.net>
In-Reply-To
<xmqqbn1l4c87.fsf@gitster.mtv.corp.google.com>
On Mon, Jul 25, 2016 at 02:52:24PM -0700, Junio C Hamano wrote:
Show 38 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> >   if (!*found_pack) {
> >     ... first find! fill in found pack, etc ...
> >   }
> >   if (exclude)
> > 	return 1;
> >   if (incremental)
> > 	return 0;
> >   if (!ignore_packed_keep && !local)
> > 	break; /* effectively return 1, but I think the break is more clear */
> >   if (local && !p->pack_local)
> > 	return 0;
> >   if (ignore_packed_keep && p->pack_local && p->pack_keep)
> > 	return 0;
> >
> > which just bumps it up. I don't think there is a way to make it more
> > elegant, e.g., by only checking ignore_packed_keep once, because we have
> > to distinguish between each condition being set independently, or the
> > case where neither is set.
> >
> > So I stuck the new check at the end, because to me logically it was "can
> > we break out of the loop instead of looking at p->next". But I agree it
> > would be equivalent to place it before the related checks, and I don't
> > mind doing that if you think it's more readable.
> 
> 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.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 13 in “speed up "Counting objects" when there are many packs”
  1. 0/2 speed up "Counting objects" when there are many packsJeff King, Jul 25, 2016
  2. 1/2 pack-objects: break out of want_object loop earlyJeff King, Jul 25, 2016
  3. Junio C HamanoJul 25, 2016
  4. Jeff KingJul 25, 2016
  5. Junio C HamanoJul 25, 2016
  6. Jeff KingJul 25, 2016
  7. Junio C HamanoJul 26, 2016
  8. Jeff KingJul 26, 2016
  9. Junio C HamanoJul 26, 2016
  10. Jeff KingJul 27, 2016
  11. Junio C HamanoJul 27, 2016
  12. Jeff KingJul 27, 2016
  13. 2/2 pack-objects: compute local/ignore_pack_keep earlyJeff King, Jul 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.