git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Sebastian Schuberth <sschuberth@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	John Keeping <john@keeping.me.uk>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Git Mailing List <git@vger.kernel.org>,
	Karsten Blees <karsten.blees@gmail.com>
Subject: Re: [PATCH] git-compat-util: Avoid strcasecmp() being inlined
Date: Thu, 12 Sep 2013 16:22:46 -0400	[thread overview]
Message-ID: <20130912202246.GF32069@sigill.intra.peff.net> (raw)
In-Reply-To: <CAHGBnuPzzokV7YMrx0gAL1VACcmaLwFoaB3n6bX8Y-UDHs7S8A@mail.gmail.com>

On Thu, Sep 12, 2013 at 09:46:51PM +0200, Sebastian Schuberth wrote:

> > Right, option 3 seems perfectly reasonable to me, as we must be prepared
> > to cope with a decision not to inline the function, and there has to be
> > _some_ linked implementation. But shouldn't libc be providing an
> > external, linkable strcasecmp in this case?
> 
> MinGW / GCC is not linking against libc, but against MSVCRT, Visual
> Studio's C runtime. And in fact MSVCRT has a non-inline implementation
> of a "case-insensitive string comparison for up to the first n
> characters"; it just happens to be called "_strnicmp", not
> "strncasecmp". Which is why I still think just having a "#define
> strncasecmp _strnicmp" is the most elegant solution to the problem.
> And that's exactly what defining __NO_INLINE__ does. Granted, defining
> __NO_INLINE__ in the scope of string.h will also add a "#define
> strcasecmp _stricmp"; but despite it's name, defining __NO_INLINE__
> does not imply a performance hit due to functions not being inlined
> because it's just the "strncasecmp" wrapper around "_strnicmp" that's
> being inlined, not "_strnicmp" itself.

Ah, thanks, that explains what is going on. I do think the environment
is probably in violation of C99, but I dug in the mingw history, and it
looks like it has been this way for over 10 years.

So it is probably worth working around, but it would be nice if the
damage could be contained to just the affected platform.

I think there are basically three classes of solution:

  1. Declare __NO_INLINE__ everywhere. I'd worry this might affect other
     environments, who would then not inline and lose performance (but
     since it's a non-standard macro, we don't really know what it will
     do in other places; possibly nothing).

  2. Declare __NO_INLINE__ on mingw. Similar to above, but we know it
     only affects mingw, and we know the meaning of NO_INLINE there.

  3. Try to impact only the uses as a function pointer (e.g., by using
     a wrapper function as suggested in the thread).

Your patch does (1), I believe. Junio's patch does (3), but is a
maintenance burden in that any new callsites will need to remember to do
the same trick.

But your argument (and reading the mingw header, I agree) is that there
is no performance difference at all between (2) and (3). And (2) does
not have the maintenance burden. So it does seem like the right path to
me.

-Peff

  reply	other threads:[~2013-09-12 20:22 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-11 16:06 [PATCH] git-compat-util: Avoid strcasecmp() being inlined Sebastian Schuberth
2013-09-11 18:29 ` Jonathan Nieder
2013-09-11 19:16   ` Jeff King
2013-09-19  6:04     ` Piotr Krukowiecki
     [not found]       ` <CAPc5daVt4Q9twub5KyOQqZHx9CwOnkuwA97sXV44fF2j1e5HVg@mail.gmail.com>
2013-09-19  9:47         ` Piotr Krukowiecki
2013-09-19 21:16           ` Jeff King
2013-09-19 22:03             ` Junio C Hamano
2013-09-19 22:05               ` Jeff King
2013-09-19 22:40                 ` Junio C Hamano
2013-09-20  3:18                   ` Jeff King
2013-09-20  6:21             ` Piotr Krukowiecki
2013-09-24  5:32               ` Jeff King
2013-09-11 19:59   ` Sebastian Schuberth
2013-09-11 21:41     ` Jeff King
2013-09-12  9:36       ` Sebastian Schuberth
2013-09-12 10:14         ` John Keeping
2013-09-12 15:37           ` Junio C Hamano
2013-09-12 18:20             ` Jeff King
2013-09-12 18:35               ` Junio C Hamano
2013-09-12 18:38                 ` Jonathan Nieder
2013-09-12 19:51                   ` Sebastian Schuberth
2013-09-12 20:08                     ` Junio C Hamano
2013-09-13 12:33                       ` Sebastian Schuberth
2013-09-13 14:26                         ` Junio C Hamano
2013-09-13 19:34                           ` Sebastian Schuberth
2013-09-12 21:36                     ` Jonathan Nieder
2013-09-12 19:00                 ` Jeff King
2013-09-12 19:46               ` Sebastian Schuberth
2013-09-12 20:22                 ` Jeff King [this message]
2013-09-12 20:29                   ` Junio C Hamano
2013-09-13 12:47                     ` Sebastian Schuberth
2013-09-13 14:37                       ` Junio C Hamano
2013-09-13 19:53                         ` Sebastian Schuberth
2013-09-13 19:56                           ` Linus Torvalds
2013-09-13 20:03                             ` Sebastian Schuberth
2013-09-13 20:01                           ` Junio C Hamano
2013-09-13 20:04                             ` Sebastian Schuberth
2013-09-13 22:06                               ` Junio C Hamano
2013-09-13 22:35                                 ` Junio C Hamano
2013-09-15 12:44                                 ` Sebastian Schuberth
2013-09-17 16:17                                   ` Junio C Hamano
2013-09-17 19:16                                     ` Sebastian Schuberth
2013-09-17 21:46                                       ` Junio C Hamano
2013-09-18  9:43                                         ` Sebastian Schuberth
2013-09-18 12:19                                           ` Linus Torvalds
2013-09-12 21:31                 ` Jonathan Nieder
2013-09-19 13:47                   ` Sebastian Schuberth
2013-09-11 18:39 ` Junio C Hamano

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=20130912202246.GF32069@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=john@keeping.me.uk \
    --cc=jrnieder@gmail.com \
    --cc=karsten.blees@gmail.com \
    --cc=sschuberth@gmail.com \
    /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).