unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andrea Corallo <akrl@sdf.org>
To: Alan Mackenzie <acm@muc.de>
Cc: Rocky Bernstein <rocky@gnu.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: Correct line/column numbers in byte compiler messages
Date: Sat, 21 Mar 2020 21:08:10 +0000	[thread overview]
Message-ID: <xjfwo7dh0w5.fsf@sdf.org> (raw)
In-Reply-To: <20200321201954.GB7805@ACM> (Alan Mackenzie's message of "Sat, 21 Mar 2020 20:19:54 +0000")

[-- Attachment #1: Type: text/plain, Size: 2600 bytes --]

Alan Mackenzie <acm@muc.de> writes:

> On my Ryzen, I'm seeing a 50% penalty.  :-(  (Admittedly that's
> comparing the year old branch to current master.  I suppose I should
> build the correct comparable revision and try again.)  This suggests
> that the branch prediction logic isn't present (or isn't active) on the
> Ryzen.

This is very strange.  You cerntaly have to compare branches from the
same epoch.  I pretty sure in the last year Paul pushed changes to the
inline policy with some measureble effect on performance.

>> Interestingly with the __builtin_expect trick applied exec time gets
>> back to 50.65s.
>
> How do you do this?  I couldn't make much sense of the documentation of
> __builtin_expect.  :-(

I attach the very simple patch I tried.  Basically the compiler has an
euristic branch predictor (in GCC predict.c) that is used to order the
final basic block output.  The wanted outcome is to have the most likely
execution line as sequential, this on modern CPUs to maximize the
front-end bandwidth.  "__builtin_expect" is just a strong hint to this
predictor.

>> We could probably find a benchmark that better highlights the difference
>> (this is potentially dominated by cache misses while pointer chasing the
>> list) but is it worth?
>
> Could I ask you to do the following timing.
>
> Evaluate the following (e.g. in *scratch*):
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (defmacro time-it (&rest forms)
>   "Time the running of a sequence of forms using `float-time'.
> Call like this: \"M-: (time-it (foo ...) (bar ...) ...)\"."
>   `(let ((start (float-time)))
>     ,@forms
>     (- (float-time) start)))
>
> (defun time-scroll (&optional arg)
>   (interactive "P")
>   (message "%s"
>            (time-it
>             (condition-case nil
>                 (while t
>                   (if arg (scroll-down) (scroll-up))
>                   (sit-for 0))
>               (error nil)))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> , visit .../emacs/src/xdisp.c, and do M-: (time-scroll).  This scrolls
> through the buffer and prints a timing in the minibuffer.  (N.B. to run
> this again, type something at BOB and undo it, thus marking the
> fontification as stale.)
>
> I'm seeing 19.4s vs. 22.2s, which is around 15% difference.  :-(

I get 19.30 sec against 16.65 that is 15% difference here too.  This is
extremely interesting and would be worth profiling.

I bet on the GC for this! (Note I'm notoriously wrong when speculating
on benchmarks :)

Regards

  Andrea
  
-- 
akrl@sdf.org


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: comp-hint.patch --]
[-- Type: text/x-diff, Size: 1572 bytes --]

diff --git a/src/lisp.h b/src/lisp.h
index a22043026a..6e3cca1bbc 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -394,8 +394,12 @@ typedef EMACS_INT Lisp_Word;
 /* #define lisp_h_EQ(x, y) (XLI (x) == XLI (y)) */
 
 /* verify (NIL_IS_ZERO) */
+
+#define SYMBOLS_WITH_POS_ENABLED			\
+  __builtin_expect(symbols_with_pos_enabled, 0)
+
 #define lisp_h_EQ(x, y) ((XLI ((x)) == XLI ((y)))       \
-  || (symbols_with_pos_enabled    \
+  || (SYMBOLS_WITH_POS_ENABLED    \
   && (SYMBOL_WITH_POS_P ((x))                        \
       ? BARE_SYMBOL_P ((y))                               \
         ? (XSYMBOL_WITH_POS((x)))->sym == (y)          \
@@ -424,7 +428,7 @@ typedef EMACS_INT Lisp_Word;
 #define lisp_h_BARE_SYMBOL_P(x) TAGGEDP ((x), Lisp_Symbol)
 /* verify (NIL_IS_ZERO) */
 #define lisp_h_SYMBOLP(x) ((BARE_SYMBOL_P ((x)) ||               \
-                            (symbols_with_pos_enabled && (SYMBOL_WITH_POS_P ((x))))))
+                            (SYMBOLS_WITH_POS_ENABLED && (SYMBOL_WITH_POS_P ((x))))))
 #define lisp_h_TAGGEDP(a, tag) \
    (! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \
 	- (unsigned) (tag)) \
@@ -463,7 +467,7 @@ typedef EMACS_INT Lisp_Word;
 /* verify (NIL_IS_ZERO) */
 # define lisp_h_XSYMBOL(a)                      \
      (eassert (SYMBOLP ((a))),                      \
-      (!symbols_with_pos_enabled             \
+      (!SYMBOLS_WITH_POS_ENABLED             \
       ? (XBARE_SYMBOL ((a)))             \
        : (BARE_SYMBOL_P ((a)))           \
       ? (XBARE_SYMBOL ((a)))                                    \

  reply	other threads:[~2020-03-21 21:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-19 15:10 GNU is looking for Google Summer of Code Projects Rocky Bernstein
2020-03-19 17:35 ` Stefan Monnier
2020-03-19 17:56   ` Andrea Corallo
2020-03-19 18:05     ` Andrea Corallo
2020-03-19 18:19     ` Rocky Bernstein
2020-03-19 21:26     ` Stefan Monnier
2020-03-19 21:45       ` Andrea Corallo
2020-03-19 23:07         ` Rocky Bernstein
2020-03-19 20:34   ` Correct line/column numbers in byte compiler messages [Was: GNU is looking for Google Summer of Code Projects] Alan Mackenzie
2020-03-19 20:43     ` Andrea Corallo
2020-03-20 19:18       ` Alan Mackenzie
2020-03-21 11:22         ` Andrea Corallo
2020-03-21 15:30           ` Correct line/column numbers in byte compiler messages Alan Mackenzie
2020-03-21 16:28             ` Andrea Corallo
2020-03-21 18:37               ` Andrea Corallo
2020-03-21 20:19                 ` Alan Mackenzie
2020-03-21 21:08                   ` Andrea Corallo [this message]
2020-03-21 23:39                     ` Andrea Corallo
2020-03-22 11:26                   ` Alan Mackenzie
2020-03-19 20:56     ` Correct line/column numbers in byte compiler messages [Was: GNU is looking for Google Summer of Code Projects] Rocky Bernstein
2020-03-19 22:05       ` Stefan Monnier
2020-03-20 19:25       ` Alan Mackenzie
2020-03-19 21:41     ` Stefan Monnier
2020-03-19 22:09       ` Stefan Monnier
2020-03-20 20:10       ` Alan Mackenzie
2020-03-20 21:23         ` Rocky Bernstein
2020-03-20 21:27         ` Clément Pit-Claudel
2020-03-20 23:46           ` Stefan Monnier
2020-03-20 21:30         ` Stefan Monnier

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=xjfwo7dh0w5.fsf@sdf.org \
    --to=akrl@sdf.org \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rocky@gnu.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).