Re: [PATCH] git gc: Speed it up by 18% via faster hash comparisons
- From
Dmitry Potapov <dpotapov@gmail.com>
- Date
- Apr 28, 2011, 09:32 UTC
- Message-ID
- <BANLkTin+qb6j8p+kOTEkQ2iK29ZWOsRk-g@mail.gmail.com>
- In-Reply-To
- <20110427231748.GA26632@elie>
2011/4/28 Jonathan Nieder <jrnieder@gmail.com>:
Show 14 quoted lines
>
> Hm. This would be very sensitive to the compiler, since a too-smart
> optimizer could take this loop and rewrite it back to memcmp! So I
> wonder if it's possible to convey this to the compiler more precisely:
>
> return memcmp_probably_differs_early(sha1, sha2, 20);
>
> 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)It can be a problem with unalligned access. So, IMHO, it is better to use get_be32 here:
unsigned start1 = get_be32(sha1); unsigned start2 = get_be32(sha2);
if (likely(start1 != start2)) {
if (start1 < start2)...
Dmitry