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

Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 28, 2011, 09:31 UTC
Message-ID
<20110428093120.GA377@elie>
In-Reply-To
<20110428063625.GB952@elte.hu>
Ingo Molnar wrote:
> * Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 16 quoted lines
>> E.g., how would something like
>>
>> 	const unsigned int *start1 = (const unsigned int *) sha1;
>> 	const unsigned int *start2 = (const unsigned int *) sha2;
>>
>> 	if (likely(*start1 != *start2)) {
>> 		if (*start1 < *start2)
>> 			return -1;
>> 		return +1;
>> 	}
>> 	return memcmp(sha1 + 4, sha2 + 4, 16);
>>
>> perform?
>
> Note that this function wont work on like 99% of the systems out there due to 
> endianness assumptions in Git.

Yes, I was greedy and broke the semantics, and my suggestion was nonsensical for other reasons (e.g., alignment), too. I should have written something like:

	if (likely(*sha1 != *sha2)) {
		if (*sha1 < *sha2)
			return -1;
		return +1;
	}
	return memcmp(sha1, sha2, 20);
since speeding it up 255/256 times seems good enough already.
> Also, your hypothetical smart compiler would recognize the above as equivalent 
> to memcmp(sha1, sha2, 20) and could rewrite it again - so we'd be back to 
> square 1.

True. The real point is a "likely" to explain to human readers what is happening.

Show 13 quoted lines
> Having said that, it would be nice if someone could test these two patches on a 
> modern AMD box, using the perf stat from here:
>
>   http://people.redhat.com/mingo/tip.git/README
>
>   cd tools/perf/
>   make -j install
>
> and do something like this to test git gc's performance:
>
>   $ perf stat --sync --repeat 10 ./git gc
>
> ... to see whether these speedups are generic, or somehow Intel CPU specific.

Sounds like fun. Will try to find time to play around with this in the next few days.

> Well i messed up endianness in an early version of this patch and 'git gc' was
> eminently unhappy about it! I have not figured out which part of Git relies on
> the comparison result though - most places seem to use the result as a boolean.

I think hashcmp is used to run binary searches within a packfile index. Thanks for explaining.

Regards, Jonathan

Previous: Ingo MolnarNext: Ingo Molnar
Message 5 of 45 in “git gc: Speed it up by 18% via faster hash comparisons”
  1. git gc: Speed it up by 18% via faster hash comparisonsIngo Molnar, Apr 27, 2011
  2. Ingo MolnarApr 27, 2011
  3. Jonathan NiederApr 27, 2011
  4. Ingo MolnarApr 28, 2011
  5. Jonathan NiederApr 28, 2011
  6. Ingo MolnarApr 28, 2011
  7. Dmitry PotapovApr 28, 2011
  8. Junio C HamanoApr 27, 2011
  9. Ralf BaechleApr 28, 2011
  10. Bernhard R. LinkApr 28, 2011
  11. Andreas EricssonApr 28, 2011
  12. Erik Faye-LundApr 28, 2011
  13. H. Peter AnvinApr 28, 2011
  14. Ingo MolnarApr 28, 2011
  15. Erik Faye-LundApr 28, 2011
  16. Ingo MolnarApr 28, 2011
  17. Ingo MolnarApr 28, 2011
  18. Erik Faye-LundApr 28, 2011
  19. Pekka EnbergApr 28, 2011
  20. Erik Faye-LundApr 28, 2011
  21. Pekka EnbergApr 28, 2011
  22. Erik Faye-LundApr 28, 2011
  23. Pekka EnbergApr 28, 2011
  24. Jonathan NiederApr 28, 2011
  25. Erik Faye-LundApr 28, 2011
  26. Ingo MolnarApr 28, 2011
  27. Ingo MolnarApr 28, 2011
  28. Erik Faye-LundApr 28, 2011
  29. Ingo MolnarApr 28, 2011
  30. Alex RiesenApr 29, 2011
  31. H. Peter AnvinApr 29, 2011
  32. Tor ArntsenApr 28, 2011
  33. H. Peter AnvinApr 28, 2011
  34. Andreas EricssonApr 28, 2011
  35. Erik Faye-LundApr 28, 2011
  36. Ingo MolnarApr 28, 2011
  37. Nguyen Thai Ngoc DuyApr 28, 2011
  38. Erik Faye-LundApr 28, 2011
  39. Junio C HamanoApr 28, 2011
  40. Dmitry PotapovApr 28, 2011
  41. Dmitry PotapovApr 28, 2011
  42. Ingo MolnarApr 28, 2011
  43. Dmitry PotapovApr 28, 2011
  44. Ingo MolnarApr 28, 2011
  45. Ingo MolnarApr 28, 2011

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.