git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>, Jonathan Tan <jonathantanmy@google.com>
Subject: Re: [PATCH 2/2] hashcmp: use memcmp instead of open-coded loop
Date: Wed, 9 Aug 2017 16:55:43 +0200	[thread overview]
Message-ID: <2b111a78-dea4-85ff-3d8f-94d2eee0ca26@web.de> (raw)
In-Reply-To: <20170809101645.7wv4mcsmnejxzhvs@sigill.intra.peff.net>

Am 09.08.2017 um 12:16 schrieb Jeff King:
> In 1a812f3a70 (hashcmp(): inline memcmp() by hand to
> optimize, 2011-04-28), it was reported that an open-coded
> loop outperformed memcmp() for comparing sha1s.
> 
> Discussion[1] a few years later in 2013 showed that this
> depends on your libc's version of memcmp(). In particular,
> glibc 2.13 optimized their memcmp around 2011. Here are
> current timings with glibc 2.24 (best-of-five, on
> linux.git):
> 
>    [before this patch, open-coded]
>    $ time git rev-list --objects --all
>    real	0m35.357s
>    user	0m35.016s
>    sys	0m0.340s
> 
>    [after this patch, memcmp]
>    real	0m32.930s
>    user	0m32.630s
>    sys	0m0.300s

Nice.  And here's the size of the git executable in my build:

         unstripped stripped
  before    8048176  2082416
  after     8006064  2037360

> I also wondered if using memcmp() could be a hint to the compiler to use
> an intrinsic or some other trick, especially because the "len" here is a
> constant. But in a toy function compiled with "gcc -S", it looks like we
> do keep the call to memcmp (so the speedup really is glibc, and not some
> compiler magic).

GCC 7 inlines memcmp() if we only need a binary result:

	https://godbolt.org/g/iZ11Ne

René

  reply	other threads:[~2017-08-09 14:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 22:07 [PATCH] sha1_file: avoid comparison if no packed hash matches the first byte René Scharfe
2017-08-08 22:41 ` Jonathan Nieder
2017-08-08 22:43 ` Junio C Hamano
2017-08-08 22:52   ` Jeff King
2017-08-08 22:58     ` Jeff King
2017-08-09  5:36       ` Junio C Hamano
2017-08-09  9:20         ` Jeff King
2017-08-09 10:11           ` Jeff King
2017-08-09 10:14             ` [PATCH 1/2] sha1_file: drop experimental GIT_USE_LOOKUP search Jeff King
2017-08-09 18:12               ` Junio C Hamano
2017-08-09 21:09                 ` Jeff King
2017-08-09 10:16             ` [PATCH 2/2] hashcmp: use memcmp instead of open-coded loop Jeff King
2017-08-09 14:55               ` René Scharfe [this message]
2017-08-09 15:06                 ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2b111a78-dea4-85ff-3d8f-94d2eee0ca26@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).