From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Inlining policy Date: Tue, 7 Apr 2020 21:03:08 -0700 Organization: UCLA Computer Science Department Message-ID: <2818498c-24f9-0873-80d7-afd7899b68ac@cs.ucla.edu> References: <86tv2h2vww.fsf@gmail.com> <20200326193128.GC14092@ACM> <86d08y4zsx.fsf@gmail.com> <83sghs7qdz.fsf@gnu.org> <83h7y63sjj.fsf@gnu.org> <834ku43c61.fsf@gnu.org> <83k12zz6ds.fsf@gnu.org> <054393f3-3873-ab6e-b325-0eca354d8838@gmx.at> <29a6c120-f260-0ea3-f5e0-1d3dd6323d09@gmx.at> <5752c978-3a13-4e09-18b3-14201eaf1083@gmx.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0BEA0C2E6BBFAD1F4BEACA3D" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="113649"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 Cc: Stefan Monnier , emacs-devel@gnu.org To: Andrea Corallo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 08 06:03:49 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jM1wL-000TRf-1H for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Apr 2020 06:03:49 +0200 Original-Received: from localhost ([::1]:55758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jM1wK-000582-1P for ged-emacs-devel@m.gmane-mx.org; Wed, 08 Apr 2020 00:03:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44727) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jM1vn-0004hF-W7 for emacs-devel@gnu.org; Wed, 08 Apr 2020 00:03:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jM1vm-0000A7-C6 for emacs-devel@gnu.org; Wed, 08 Apr 2020 00:03:15 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:34424) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jM1vm-000078-2T for emacs-devel@gnu.org; Wed, 08 Apr 2020 00:03:14 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 34AA3160066; Tue, 7 Apr 2020 21:03:10 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id reo8y_WXWRd4; Tue, 7 Apr 2020 21:03:09 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E8236160068; Tue, 7 Apr 2020 21:03:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XMrmVRVSXkLG; Tue, 7 Apr 2020 21:03:08 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 9330A160066; Tue, 7 Apr 2020 21:03:08 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:246635 Archived-At: This is a multi-part message in MIME format. --------------0BEA0C2E6BBFAD1F4BEACA3D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 4/5/20 3:23 AM, Andrea Corallo wrote: > what about having a new macro to control the key operations we want to > always have inlined at -O0 and -Og instead of falling back into defining > these as macros? I looked into this some more, and found some problems with using __attribute__((always_inline)), such as GCC complaining that it can't inline some functions in some cases on some platforms. It was a pain to suss out what would improve performance while avoiding the warnings, and while fiddling with this a bit I found a simpler change that had even better performance than __attribute__((always_inline)) did, at least on one platform for my standard benchmark of 'make compile-always'. So I installed the two attached patches instead. Together they improve Emacs CPU performance for 'gcc -Og' by about 60% on my benchmark. I kept the DEFINE_KEY_OPS_AS_MACROS stuff because of the -O0 performance issues that we discussed earlier. Once we no longer need to worry about -O0 performance when debugging, we can get rid of that stuff. Thanks for suggesting inlining as a way to improve Emacs performance when compiled with -Og. --------------0BEA0C2E6BBFAD1F4BEACA3D Content-Type: text/x-patch; charset=UTF-8; name="0001-Improve-inlining-when-compiling-with-Og.patch" Content-Disposition: attachment; filename="0001-Improve-inlining-when-compiling-with-Og.patch" Content-Transfer-Encoding: quoted-printable >From b9b32074cecb0e0d20cf527eadacbb0b7f5cced9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Apr 2020 16:57:04 -0700 Subject: [PATCH 1/2] Improve inlining when compiling with -Og MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * src/conf_post.h (EXTERN_INLINE) [!EMACS_EXTERN_INLINE]: Make it static inline, not merely static. This is a worthwhile performance improvement on my two platforms A and B (see below). On my platform A this change improves user+system CPU performance of =E2=80=98make compile-always=E2=80=99 by 52% on an -Og build, and by 1.4%= on the default -O2 build. On my platform B this improves the same benchmark by 41% on an -Og build, and by -0.8% on the default -O2 build. That "-0.8%" is a small negative for this change, and I recall that it is why I didn't make this change earlier. However, Platform B uses an older GCC so we needn't worry overmuch about this small negative. With this change the performance advantage of -O2 over -Og has dropped on platform A; formerly -O2 was 87% faster than -Og, and now it is only 25% faster. On platform B the performance advantage of -O2 over -Og has dropped from being 62% faster to being 14% faster. Platform A is GCC 9.3.1 20200317 (Red Hat 9.3.1-1) on Fedora 31 x86-64 (AMD Phenom II X4 910e, circa 2010). Platform B is GCC (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 on Ubuntu 18.04.4 (Intel Xeon E3-1225 V2, circa 2012). This patch was inspired by a suggestion by Andrea Corallo in: https://lists.gnu.org/r/emacs-devel/2020-04/msg00263.html --- src/conf_post.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/conf_post.h b/src/conf_post.h index eb8fb18c00..79fb4cfe8a 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -432,15 +432,13 @@ extern int emacs_setenv_TZ (char const *); =20 #else =20 -/* Use 'static' instead of 'extern inline' because 'static' typically - has better performance for Emacs. Do not use the 'inline' keyword, - as modern compilers inline automatically. ATTRIBUTE_UNUSED - pacifies gcc -Wunused-function. */ +/* Use 'static inline' instead of 'extern inline' because 'static inline= ' + has much better performance for Emacs when compiled with 'gcc -Og'. = */ =20 # ifndef INLINE # define INLINE EXTERN_INLINE # endif -# define EXTERN_INLINE static ATTRIBUTE_UNUSED +# define EXTERN_INLINE static inline # define INLINE_HEADER_BEGIN # define INLINE_HEADER_END =20 --=20 2.17.1 --------------0BEA0C2E6BBFAD1F4BEACA3D Content-Type: text/x-patch; charset=UTF-8; name="0002-Revert-my-KEY_OPS_CFLAGS-change-to-src-Makefile.in.patch" Content-Disposition: attachment; filename*0="0002-Revert-my-KEY_OPS_CFLAGS-change-to-src-Makefile.in.patc"; filename*1="h" Content-Transfer-Encoding: quoted-printable >From c36792bd79f3a97f292ab0612aa5c3ab1b4d9e70 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Apr 2020 20:52:28 -0700 Subject: [PATCH 2/2] Revert my KEY_OPS_CFLAGS change to src/Makefile.in MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Now that -Og inlining has been improved this is no longer helpful. * src/Makefile.in (KEY_OPS_CFLAGS): Remove. All uses removed. This improved CPU performance of =E2=80=98make compile-always=E2=80=99 by= 5% on my platform, which was gcc -Og, GCC 9.3.1 20200317 (Red Hat 9.3.1-1), Fedora 31 x86-64 (AMD Phenom II X4 910e, circa 2010). --- src/Makefile.in | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index dfd322553b..552dd2e50a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -377,14 +377,11 @@ pdmp :=3D # Flags that might be in WARN_CFLAGS but are not valid for Objective C. NON_OBJC_CFLAGS =3D -Wignored-attributes -Wignored-qualifiers -Wopenmp-s= imd =20 -# Cajole GCC into inlining key ops even if it wouldn't normally. -KEY_OPS_CFLAGS =3D $(if $(filter -Og,$(CFLAGS)),-DDEFINE_KEY_OPS_AS_MACR= OS) - # -Demacs makes some files produce the correct version for use in Emacs. # MYCPPFLAGS is for by-hand Emacs-specific overrides, e.g., # "make MYCPPFLAGS=3D'-DDBUS_DEBUG'". -EMACS_CFLAGS =3D -Demacs $(KEY_OPS_CFLAGS) $(MYCPPFLAGS) \ - -I. -I$(srcdir) -I$(lib) -I$(top_srcdir)/lib \ +EMACS_CFLAGS=3D-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \ + -I$(lib) -I$(top_srcdir)/lib \ $(C_SWITCH_MACHINE) $(C_SWITCH_SYSTEM) $(C_SWITCH_X_SITE) \ $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS)= \ $(PNG_CFLAGS) $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \ --=20 2.17.1 --------------0BEA0C2E6BBFAD1F4BEACA3D--