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

Re: [PATCH v2] unpack-trees: avoid duplicate ODB lookups during checkout

From
JHJeff Hostetler <git@jeffhostetler.com>
Date
Apr 10, 2017, 21:28 UTC
Message-ID
<ed64f8fc-9cec-4c46-b9e6-9e9e4983f95a@jeffhostetler.com>
In-Reply-To
<20170410205540.wvlb7ch7bodiytmh@sigill.intra.peff.net>
On 4/10/2017 4:55 PM, Jeff King wrote:
Show 38 quoted lines
> On Sat, Apr 08, 2017 at 04:06:41PM +0200, René Scharfe wrote:
>
>>> +		} else if (i > 1 && are_same_oid(&names[i], &names[i-2])) {
>>> +			/* implicitly borrow buf[i-2] inside tree_desc[i] */
>>> +			memcpy(&t[i], &t[i-2], sizeof(struct tree_desc));
>>
>> Similar case.
>>
>>> +			buf[i] = NULL;
>>
>> What makes the previous two entries special, or differently put: Why not
>> just check *all* previous entries?  MAX_UNPACK_TREES is 8; the number of
>> comparisons would just about double in the worst case and stay the same for
>> three trees or less.  The order of four trees or more wouldn't matter
>> anymore.
>
> If I understand correctly, we've got N (up to 8) trees, and we want to
> find sets of duplicates. Adjacency doesn't matter. Aren't our options
> basically:
>
>   - look through all previous entries naively, O(N^2)
>
>   - sort the list, O(N log N); but we need the original order, so we'd
>     have to unsort at the end, too
>
>   - use a hash table, O(N) but with O(N) extra storage
>
> I know N=8 isn't very big algorithmically speaking, but it would feel
> ugly to introduce something quadratic. Especially the limit of 8 seems
> rather arbitrary. In normal cases we see at most a 3-way merge. Beyond
> that we're in octopus territory, and 8 is way too low there (I think the
> octopus strategy just unpacks one at a time and barfs if there are any
> conflicts).
>
> I assume the rationale behind "check the last 2" is just "this
> optimization will kick in reliably for all sane cases", weird octopus
> unpack-trees be damned (though reading ca885a4fe, it sounds like 4-trees
> can actually happen, but I'm not clear on how).

yeah, i didn't want to pay for the obscure (n >= 4) cases with any of the above. doing 2 or 3 gets us checkout and merge. these are the common usages.

Jeff
Previous: Jeff KingNext: Jeff Hostetler
Message 5 of 8 in “unpack-trees: avoid duplicate ODB lookups during checkout”
  1. unpack-trees: avoid duplicate ODB lookups during checkoutgit@jeffhostetler.com, Apr 7, 2017
  2. unpack-trees: avoid duplicate ODB lookups during checkoutgit@jeffhostetler.com, Apr 7, 2017
  3. René ScharfeApr 8, 2017
  4. Jeff KingApr 10, 2017
  5. Jeff HostetlerApr 10, 2017
  6. Jeff HostetlerApr 10, 2017
  7. René ScharfeApr 10, 2017
  8. Jeff HostetlerApr 11, 2017

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.