unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: "Óscar Fuentes" <ofv@wanadoo.es>
Cc: emacs-devel@gnu.org
Subject: Re: master 289000e: Merge branch 'feature/native-comp' into trunk
Date: Wed, 28 Apr 2021 14:07:14 +0000	[thread overview]
Message-ID: <YIlsEmv0leaWW/67@ACM> (raw)
In-Reply-To: <875z08n79y.fsf@telefonica.net>

Hello, Óscar.

On Mon, Apr 26, 2021 at 22:02:49 +0200, Óscar Fuentes wrote:
> Alan Mackenzie <acm@muc.de> writes:

> >> C code is opaque to native-comp and puts a hard limit on how much it can
> >> optimize Elisp. Thus I hope that in the future more and more code will
> >> be moved from C to Elisp.

> > Does that make sense?  To move time critical code from fast C to slow
> > Lisp, and then optimise it back, partly?

> Calling C is a bit slow, but that's not the worst problem it introduces.
> When a call to a C function is made, the native-comp optimizer must
> throw away information it learned about the Elisp code it was compiling,
> hence reducing optimization opportunities. Furthermore, the C function
> must know how to many cases while only one or a few of them make sense
> at any given call site.

You're suggesting optimisation between Lisp functions.  I'm sceptical
about how much that could win.

> Consider this extreme example:

> (defun foo (x)
>   (+ x 12))
  
> (defun the-answer-p (x)
>   (or (and (stringp x) (string= x "42"))
>       (and (numberp x) (= x 42))
>       (and (bufferp x) ... etc)))

> (let ((a 30))
>   (if (the-answer-p (foo a))
>       (message "The answer is %d" (foo a))
>     (message "We remain ignorant")))

> The optimizer knows that the argument passed to `foo' is `a', which
> holds the constant `30'. It also knows that the value returned by `foo'
> only depends on its argument, so it can simply replace those calls to
> `foo' with (+ 30 12), and then with its result: 42. Then, on the call to
> `the-answer-p', the optimizer knows that the argument is the numeric
> constant 42, hence the second condition is true, so it can replace
> `(the-answer-p (foo a))' with `true', and then colapse the `if' to just

> (message "The answer is %d" 42)

This sort of thing is surely untypical in Emacs.

> If `foo' and `the-answer-p' were implemented on C, none of this
> optimizations could be possible, because the optimizer would know
> nothing about the inner workings of those functions.

> I'm no Elisp expert, so the above might not fully translate to what is
> achievable in practice by native-comp, but the general point holds.

> >> And other areas can benefit too: one thing which IMO has lots of
> >> potential is to native-compile regexps.

> > Again, how would that work?  Regexps are already handled in C.  How
> > could native compilation of Lisp add anything?

> Not native compilation of Elisp, but native compilation of the regexps:
> a function is generated that implements the regexp. Instead of passing
> the regexp to the engine, the function is called.

OK, I see what you mean, now.  Currently, if I understand correctly,
regexps are compiled into an interpreted language at runtime, and they
are stored in a (fairly large) cache indexed by the regexp string.

When would you compile the regexps into native code?  For constant
regexps this can be done at build time, but there are regexps
constructed at run time in Emacs.  This compilation of regexps at run
time might negate the advantages in speed that the complation would
otherwise bring.

-- 
Alan Mackenzie (Nuremberg, Germany).



  reply	other threads:[~2021-04-28 14:07 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210425182503.25223.81072@vcs0.savannah.gnu.org>
     [not found] ` <20210425182508.6CC7C2094D@vcs0.savannah.gnu.org>
2021-04-25 18:36   ` master 289000e: Merge branch 'feature/native-comp' into trunk Andrea Corallo via Emacs development discussions.
2021-04-25 18:40     ` Eli Zaretskii
2021-04-25 18:59       ` Andrea Corallo via Emacs development discussions.
2021-04-25 20:25         ` Eli Zaretskii
2021-04-25 18:45     ` Óscar Fuentes
2021-04-25 20:03     ` Alan Mackenzie
2021-04-25 20:14       ` Eli Zaretskii
2021-04-25 21:55         ` Alan Mackenzie
2021-04-26 11:40           ` Eli Zaretskii
2021-04-26 13:21             ` Alan Mackenzie
2021-04-26 13:45               ` Eli Zaretskii
2021-04-26 14:54                 ` Alan Mackenzie
2021-04-26 15:12                   ` Eli Zaretskii
2021-04-26 17:02                     ` Alan Mackenzie
2021-04-26 17:13                       ` Stefan Monnier
2021-04-26 17:25                       ` Eli Zaretskii
2021-04-28 11:34                         ` Alan Mackenzie
2021-04-28 12:26                           ` Eli Zaretskii
2021-04-28 12:32                             ` Alan Mackenzie
2021-04-28 13:01                               ` Eli Zaretskii
2021-04-28 19:09                               ` Andrea Corallo via Emacs development discussions.
2021-04-26 15:33                   ` Óscar Fuentes
2021-04-26 15:58                     ` Eli Zaretskii
2021-04-26 16:30                       ` Óscar Fuentes
2021-04-26 17:11                     ` Alan Mackenzie
2021-04-26 20:02                       ` Óscar Fuentes
2021-04-28 14:07                         ` Alan Mackenzie [this message]
2021-04-28 15:10                           ` Óscar Fuentes
2021-04-26 15:37                   ` Stefan Monnier
2021-04-26 16:06                   ` Andrea Corallo via Emacs development discussions.
2021-04-26 17:05                     ` Alan Mackenzie
2021-04-25 21:48     ` Stefan Monnier
2021-04-25 22:41     ` Stefan Kangas
2021-04-25 22:57     ` Clément Pit-Claudel
2021-04-26 16:16       ` Andrea Corallo via Emacs development discussions.
2021-04-26 13:03     ` wilde
2021-04-26 13:18     ` Minimal recommended version of gcc/libgccjit for native-comp (was: master 289000e: Merge branch 'feature/native-comp' into trunk) wilde
2021-04-26 15:58       ` Minimal recommended version of gcc/libgccjit for native-comp Stefan Monnier
2021-04-26 16:16         ` Eli Zaretskii
2021-04-26 16:32           ` Andrea Corallo via Emacs development discussions.
2021-04-26 16:54             ` Eli Zaretskii
2021-04-26 20:53               ` Andrea Corallo via Emacs development discussions.
2021-04-27  3:52               ` Richard Stallman
2021-04-26 16:18         ` Andrea Corallo via Emacs development discussions.
2021-04-26 16:12       ` Andrea Corallo via Emacs development discussions.
2021-04-27 14:21         ` wilde
2021-04-27 16:35           ` Andrea Corallo via Emacs development discussions.

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=YIlsEmv0leaWW/67@ACM \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=ofv@wanadoo.es \
    /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).