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

Re: [PATCH v3] fetch-pack: always allow fetching of literal SHA1s

From
JTJonathan Tan <jonathantanmy@google.com>
Date
May 11, 2017, 17:51 UTC
Message-ID
<695d833e-9ef1-4d74-265e-f5e3af8a54cd@google.com>
In-Reply-To
<20170511094635.ljpwg3bxkqj2wmgc@sigill.intra.peff.net>

Thanks for your suggestions. I'll hold off on sending out a new patch (following Jonathan Nieder's suggestions [1]) until we decide if further optimizations (for example, as suggested by Peff) need to be done.

[1] <20170510232231.GC28740@aiede.svl.corp.google.com>
On 05/11/2017 02:46 AM, Jeff King wrote:
Show 36 quoted lines
> On Wed, May 10, 2017 at 03:11:57PM -0700, Jonathan Tan wrote:
>
>> After looking at ways to solve jrnieder's performance concerns, if we're
>> going to need to manage one more item of state within the function, I
>> might as well use my earlier idea of storing unmatched refs in its own
>> list instead of immediately freeing them. This version of the patch
>> should have much better performance characteristics.
>
> Hrm. So the problem in your original was that the loop became quadratic
> in the number of refs when fetching all of them (because the original
> relies on the sorting to essentially do a list-merge). Are there any
> quadratic bits left?
>
>> @@ -649,6 +652,25 @@ static void filter_refs(struct fetch_pack_args *args,
>>
>>  		if ((allow_unadvertised_object_request &
>>  		    (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1))) {
>> +			can_append = 1;
>> +		} else {
>> +			struct ref *u;
>> +			/* Check all refs, including those already matched */
>> +			for (u = unmatched; u; u = u->next) {
>> +				if (!oidcmp(&ref->old_oid, &u->old_oid)) {
>> +					can_append = 1;
>> +					goto can_append;
>> +				}
>> +			}
>
> This is inside the nr_sought loop. So if I were to do:
>
>   git fetch origin $(git ls-remote origin | awk '{print $1}')
>
> we're back to being quadratic. I realize that's probably a silly thing
> to do, but in the general case, you're O(m*n), where "n" is number of
> unmatched remote refs and "m" is the number of SHA-1s you're looking
> for.

The original patch was quadratic regardless of whether we're fetching names or SHA-1s, which can be said to be bad since it is a regression in an existing and common use case (and I agree). This one is O(m*n), as you said - the "quadratic-ness" only kicks in if you fetch SHA-1s, which before this patch is impossible.

Show 5 quoted lines
> Doing better would require either sorting both lists, or storing the
> oids in something that has better than linear-time lookup.  Perhaps a
> sha1_array or an oidset? We don't actually need to know anything about
> the unmatched refs after the first loop. We just need the list of oids
> that let us do can_append.

Having a sha1_array or oidset would require allocation (O(n log n) time, I think, in addition to O(n) space) and this cost would be incurred regardless of how many SHA-1s were actually fetched (if m is an order of magnitude less than log n, for example, having a sha1_array might be actually worse). Also, presumably we don't want to incur this cost if we are fetching zero SHA-1s, so we would need to do some sort of pre-check. I'm inclined to leave it the way it is and consider this only if the use case of fetching many SHA1-s comes up.

> AIUI, you could also avoid creating the unmatched list entirely when the
> server advertises tip/reachable sha1s. That's a small optimization, but
> I think it may actually make the logic clearer.

If you mean adding an "if" block at the point where we add the unmatched ref to the unmatched list (that either adds it to the list or immediately frees it), I think it makes the logic slightly more complicated. Or maybe you had something else in mind?

Previous: Jeff KingNext: Jeff King
Message 21 of 47 in “fetch-pack: always allow fetching of literal SHA1s”
  1. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 9, 2017
  2. Jeff KingMay 9, 2017
  3. Shawn PearceMay 10, 2017
  4. Jeff KingMay 10, 2017
  5. Shawn PearceMay 10, 2017
  6. Mike HommeyMay 10, 2017
  7. Ævar Arnfjörð BjarmasonMay 10, 2017
  8. Jonathan NiederMay 10, 2017
  9. Martin FickMay 10, 2017
  10. Jonathan NiederMay 10, 2017
  11. Jonathan NiederMay 10, 2017
  12. Sebastian SchuberthMay 10, 2017
  13. Jeff KingMay 11, 2017
  14. Jonathan NiederMay 11, 2017
  15. Jeff KingMay 11, 2017
  16. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 10, 2017
  17. Jonathan NiederMay 10, 2017
  18. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 10, 2017
  19. Jonathan NiederMay 10, 2017
  20. Jeff KingMay 11, 2017
  21. Jonathan TanMay 11, 2017
  22. Jeff KingMay 11, 2017
  23. Jeff KingMay 11, 2017
  24. Brandon WilliamsMay 11, 2017
  25. Jeff KingMay 13, 2017
  26. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 11, 2017
  27. Jonathan NiederMay 11, 2017
  28. Jeff KingMay 11, 2017
  29. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 11, 2017
  30. Jonathan NiederMay 11, 2017
  31. Jeff KingMay 12, 2017
  32. Junio C HamanoMay 12, 2017
  33. Jeff KingMay 12, 2017
  34. Jonathan TanMay 12, 2017
  35. Jonathan NiederMay 12, 2017
  36. Jeff KingMay 12, 2017
  37. Jonathan TanMay 12, 2017
  38. Jeff KingMay 13, 2017
  39. Jeff KingMay 12, 2017
  40. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 12, 2017
  41. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 12, 2017
  42. Jonathan NiederMay 12, 2017
  43. Jeff KingMay 13, 2017
  44. Junio C HamanoMay 15, 2017
  45. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 15, 2017
  46. Jonathan NiederMay 15, 2017
  47. Jeff KingMay 15, 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.