unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: Emacs Lisp JIT Compiler
@ 2016-12-11 17:37 Nickolas Lloyd
  2016-12-12  6:07 ` John Wiegley
  0 siblings, 1 reply; 60+ messages in thread
From: Nickolas Lloyd @ 2016-12-11 17:37 UTC (permalink / raw)
  To: burton.samograd, emacs-devel

Burton Samograd wrote:
> By showing this ida/work I’m hoping not to get it included in emacs
> proper, but to show a relatively simple way to speed things up.  I’m
> sure there are better/alternate implementations that would both be
> cleaner and give better speedups, but this was as far as this POC went
> so far.

Coincidentally, for the past few weeks I've been working on a very
similar idea, with a slightly different implementation.  Instead of
every instruction compiling down to a function call that directly mimics
the interpreter, in many places those intermediate functions are removed
and replaced by direct calls to e.g. Ffuncall, Fconcat, etc.  Instead of
adding a new instruction to replace the original bytecode, a pointer to
the function is stashed away inside of the bytecode vector.  Other than
that it looks to be largely similar.

The code is in a repo at:

    https://github.com/smindinvern/emacs.git
    
in branch `elc-jit'.  It's based off of emacs-25, and so far during my
testing enabling the JIT globally seems to be stable. There seem to be
some performance penalties with that, though, due to some functions
which are byte-compiled many times at runtime....  I was able to produce
gains of 15-20% on your ray-tracing benchmark, though, so there is a
significant speedup for individual functions.

I bring this up, for those interested, because it is fully working with
a recent version of emacs.  Maybe there are some things that could be
learned from each implementation?

I've also looked into using libgccjit, though the object model seems a
bit more complicated, with distinctions made between lvalues, rvalues,
etc.  I'll probably do some work on porting my code to libgccjit at some
point to see how the performance compares.

Thanks,
Nick






^ permalink raw reply	[flat|nested] 60+ messages in thread
* Emacs Lisp JIT Compiler
@ 2018-08-13  4:01 Tom Tromey
  2018-08-13  5:37 ` Paul Eggert
                   ` (4 more replies)
  0 siblings, 5 replies; 60+ messages in thread
From: Tom Tromey @ 2018-08-13  4:01 UTC (permalink / raw)
  To: emacs-devel

Hi.  I've written a JIT compiler for Emacs Lisp, and I'd like to check
it in.

This JIT is based on GNU libjit, like some other attempts that have come
before it.  However, this one is somewhat faster than those, primarily
because it does all stack manipulations at compile time, not runtime.

In some simple benchmarks, it is about 3x faster than the bytecode
interpreter.

I have only tested this on x86-64.  Whether or not the JIT works on a
given platform is primarily up to libjit.  (I suspect the JIT won't work
on x86 with --with-wide-int; but that is something I could fix.)

I currently have the JIT set up to always compile all eligible functions
(that is, just byte-compiled, lexically-bound functions).  It's robust
enough that, as far as I can tell, everything works fine in this mode.
It would be possible to have it be a bit lazier, say only compile after
100 invocations, or something like that.

Aside from the possible --with-wide-int thing, there are two bugs I know
of.

First, libjit never frees functions.  So, if a function is JIT-compiled
and then redefined, the old JIT code will linger.  It's possible to fix
this with a custom allocator and a libjit patch (that I sent but that
hasn't been checked in yet).

Second, I haven't gotten around to emulating the "quitcounter" behavior
in the bytecode interpreter.  This seems straightforward.


This version of the compiler is pretty basic.  It just compiles each
bytecode to more or less the obvious thing.  I have some plans to make
the calling convention a bit less expensive, and to allow for inlining.

Note that this change does not involve any semantic changes to Emacs Lisp.
Also, if libjit is unavailable, the JIT is simply disabled.

Tom



^ permalink raw reply	[flat|nested] 60+ messages in thread
* Emacs Lisp JIT Compiler
@ 2016-12-05 18:16 Burton Samograd
  2016-12-05 18:40 ` Eli Zaretskii
  2016-12-05 19:32 ` Daniel Colascione
  0 siblings, 2 replies; 60+ messages in thread
From: Burton Samograd @ 2016-12-05 18:16 UTC (permalink / raw)
  To: Emacs developers

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

Hello,

I’ve published my Emacs Lisp JIT compiler for comments and review:

    https://github.com/burtonsamograd/emacs-jit

The JIT compiler implements a strategy of turning the byte code execution loop into a series of function calls, moving the overhead of the loop into the CPU execution unit.  I call this ‘compiling down the spine’ of the byte code vector.  No other changes have been done to the byte code instructions other than to map them to the new execution strategy.

This is work in progress and about ~90% complete and was done about 4 years ago, so it’s quite a bit off of HEAD right now.  It ‘works’ to the point of being able to JIT compile and run my included ray-tracer with a 25% speed improvement.  Enabling full JIT during compilation shows bugs and will fail; I haven’t been able to track down the cause of these failures yet.

By default, this build will provide the Lisp function 'jit-compile’ which takes a lambda expression or a symbol.

A new byte code instruction has been added Bjitcall.  When a function is JIT compiled, it’s code vector is replaced by the single Bjitcall instruction followed by the JIT compiled code block.

I have already attempted to contact assign@fsf.org<mailto:assign@fsf.org> to file my papers and was asked on Reddit to contribute this to a branch, which I am willing to do once the paperwork is done.

—
Burton Samograd

[-- Attachment #2: Type: text/html, Size: 2239 bytes --]

^ permalink raw reply	[flat|nested] 60+ messages in thread

end of thread, other threads:[~2018-09-13  4:32 UTC | newest]

Thread overview: 60+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-11 17:37 Emacs Lisp JIT Compiler Nickolas Lloyd
2016-12-12  6:07 ` John Wiegley
2016-12-12 11:51   ` Nickolas Lloyd
2016-12-12 16:45     ` John Wiegley
2016-12-23 17:22       ` Nickolas Lloyd
2016-12-13 22:24   ` Johan Bockgård
  -- strict thread matches above, loose matches on Subject: below --
2018-08-13  4:01 Tom Tromey
2018-08-13  5:37 ` Paul Eggert
2018-08-13 15:15   ` Tom Tromey
2018-08-14  0:16   ` Tom Tromey
2018-08-14 20:11     ` Daniel Colascione
2018-08-14 20:55       ` Paul Eggert
2018-08-14 21:03         ` Daniel Colascione
2018-08-14 22:38           ` Paul Eggert
2018-08-15 16:41             ` Eli Zaretskii
2018-08-15 17:16               ` Paul Eggert
2018-08-15 17:47                 ` Eli Zaretskii
2018-08-16  0:29               ` Tom Tromey
2018-08-16 13:26                 ` Eli Zaretskii
2018-08-16 15:43                   ` Daniel Colascione
2018-08-16 16:22                     ` Andreas Schwab
2018-08-19 18:17                     ` Tom Tromey
2018-08-19 19:00                       ` Eli Zaretskii
2018-08-19 19:16                         ` Tom Tromey
2018-08-19 20:23                       ` Stefan Monnier
2018-08-18 10:10                   ` Steinar Bang
2018-08-18 11:31                     ` Eli Zaretskii
2018-08-19 10:00                       ` Robert Pluim
2018-08-19 15:01                         ` Eli Zaretskii
2018-08-19 15:26                   ` Tom Tromey
2018-08-23  0:47                 ` Tom Tromey
2018-08-23 16:48                   ` Eli Zaretskii
2018-08-24 17:54                     ` Tom Tromey
2018-08-24 20:23                       ` Eli Zaretskii
2018-08-24 21:03                         ` Tom Tromey
2018-08-25  6:51                           ` Eli Zaretskii
2018-09-10 11:03                             ` Ergus
2018-09-10 11:15                               ` Robert Pluim
2018-09-10 11:53                                 ` Tom Tromey
2018-09-12 13:37                                   ` Robert Pluim
2018-09-13  4:32                                     ` Tom Tromey
2018-08-16  0:03   ` Tom Tromey
2018-08-16  2:45     ` Eli Zaretskii
2018-08-16 18:07       ` Eli Zaretskii
2018-08-13 13:50 ` T.V Raman
2018-08-13 15:18   ` Tom Tromey
2018-08-13 15:23     ` T.V Raman
2018-08-13 15:15 ` Eli Zaretskii
2018-08-20 21:54   ` John Wiegley
2018-08-13 23:31 ` Richard Stallman
2018-08-13 23:51   ` Tom Tromey
2018-08-16  2:42     ` Richard Stallman
2018-08-15  0:21 ` Clément Pit-Claudel
2018-08-16  0:32   ` Tom Tromey
2018-08-16  2:14     ` Clément Pit-Claudel
2016-12-05 18:16 Burton Samograd
2016-12-05 18:40 ` Eli Zaretskii
2016-12-05 19:32 ` Daniel Colascione
2016-12-05 21:03   ` Burton Samograd
2016-12-06 15:54     ` Lluís

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).