unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Compiling byte code to native
@ 2004-06-02 11:43 Matthew Mundell
  2004-06-02 14:22 ` Stefan Monnier
  2004-06-02 22:56 ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Matthew Mundell @ 2004-06-02 11:43 UTC (permalink / raw)


The native compilation effort introduced earlier this year is archived
at http://www.mundell.ukfsn.org/native.  It can now compile all the
byte codes.


Here are three speed comparisons.  The commas in the middle column
separate runs.

               microseconds                    size in bytes
copy-tree
   Byte       21, 21, 20, 21, 18                    100
   Native     28, 14, 14, 16, 17                   2332

last
   Byte       15, 15, 16, 14, 15, 14                 65
   Native     12, 12, 12, 13, 19, 9                1605

native-test-info-eg-loop-small [1]
   Byte       187, 231, 233, 235, 235, 237, 485      13
   Native     113, 158, 164, 172, 173, 186, 225     302

So the speedup over byte code is available, but it seems that in most
cases it will be over-shadowed by the time spent in primitives.


It may be good to update the TODO entry:

** Investigate using GNU Lightning or similar system for incremental
   compilation of selected bytecode functions to subrs.  [There is an
   effort archived at http://www.mundell.ukfsn.org/native that can
   compile byte-code functions to native.]

In the future perhaps this work could be a base or reference for
adding compilation of functions to primitives.


Thanks.


[1] Passing 1000 to:

(defun native-test-info-eg-small (n)
  "Return time before and after N iterations of a loop.
This is the info manual's byte code speed example."
  (let ((t1 (current-time-string)))
    (while (> (setq n (1- n))
	      0))
    (list t1 (current-time-string))))

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

* Re: Compiling byte code to native
  2004-06-02 11:43 Compiling byte code to native Matthew Mundell
@ 2004-06-02 14:22 ` Stefan Monnier
  2004-06-02 16:30   ` Matthew Mundell
  2004-06-02 22:56 ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2004-06-02 14:22 UTC (permalink / raw)
  Cc: emacs-devel

> The native compilation effort introduced earlier this year is archived
> at http://www.mundell.ukfsn.org/native.  It can now compile all the
> byte codes.

The speedups are disappointing, but I'm not surprised: most byte-code
operations end up calling non-trivial C functions.

Maybe the results would be a bit more encouraging if you tried to compile
lexbind byte-code (where local variables are kept on the byte-code stack
rather than being varbound&varref'd).


        Stefan

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

* Re: Compiling byte code to native
  2004-06-02 14:22 ` Stefan Monnier
@ 2004-06-02 16:30   ` Matthew Mundell
  2004-06-02 17:04     ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Matthew Mundell @ 2004-06-02 16:30 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> > The native compilation effort introduced earlier this year is archived
> > at http://www.mundell.ukfsn.org/native.  It can now compile all the
> > byte codes.
> 
> The speedups are disappointing, but I'm not surprised: most byte-code
> operations end up calling non-trivial C functions.
> 
> Maybe the results would be a bit more encouraging if you tried to compile
> lexbind byte-code (where local variables are kept on the byte-code stack
> rather than being varbound&varref'd).

This would be quite similar to compiling to a primitive, where the
arguments will have to be lexically scoped.  It may show an
improvement over the standard byte-code, but the lexbind byte-code may
show a similar improvement.

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

* Re: Compiling byte code to native
  2004-06-02 16:30   ` Matthew Mundell
@ 2004-06-02 17:04     ` Stefan Monnier
  2004-06-02 18:05       ` Matthew Mundell
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2004-06-02 17:04 UTC (permalink / raw)
  Cc: emacs-devel

>> Maybe the results would be a bit more encouraging if you tried to compile
>> lexbind byte-code (where local variables are kept on the byte-code stack
>> rather than being varbound&varref'd).

> This would be quite similar to compiling to a primitive, where the
> arguments will have to be lexically scoped.  It may show an
> improvement over the standard byte-code, but the lexbind byte-code may
> show a similar improvement.

I do expect lexbind byte-code to be slightly faster than dynbind byte-code,
but I also expect that the speed up you get from compilation to native code
will be even larger with lexbind byte-code than with dynbind byte-code.

This is because lexbind byte-code uses more stack-access operations which
are very simple and thus quick to execute and because such quick byte-code
operations have a relatively larger interpretive overhead (because the
overhead is constant per operations, so it's relatively higher for simple
operations).


        Stefan

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

* Re: Compiling byte code to native
  2004-06-02 17:04     ` Stefan Monnier
@ 2004-06-02 18:05       ` Matthew Mundell
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Mundell @ 2004-06-02 18:05 UTC (permalink / raw)
  Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> >> Maybe the results would be a bit more encouraging if you tried to compile
> >> lexbind byte-code (where local variables are kept on the byte-code stack
> >> rather than being varbound&varref'd).
> 
> > This would be quite similar to compiling to a primitive, where the
> > arguments will have to be lexically scoped.  It may show an
> > improvement over the standard byte-code, but the lexbind byte-code may
> > show a similar improvement.
> 
> I do expect lexbind byte-code to be slightly faster than dynbind byte-code,
> but I also expect that the speed up you get from compilation to native code
> will be even larger with lexbind byte-code than with dynbind byte-code.
> 
> This is because lexbind byte-code uses more stack-access operations which
> are very simple and thus quick to execute and because such quick byte-code
> operations have a relatively larger interpretive overhead (because the
> overhead is constant per operations, so it's relatively higher for simple
> operations).

Right, I get what you're saying: the smaller lexbind variable ops will
reduce the time spent in primitives, which favours the native
functions.  And the frequent use of the variable operations may make
the improvement substantial.

It's a bit much for me to try now, so I'll consider it again in a few
weeks time.

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

* Re: Compiling byte code to native
  2004-06-02 11:43 Compiling byte code to native Matthew Mundell
  2004-06-02 14:22 ` Stefan Monnier
@ 2004-06-02 22:56 ` Richard Stallman
  2004-06-03 10:32   ` Matthew Mundell
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2004-06-02 22:56 UTC (permalink / raw)
  Cc: emacs-devel

I simply deleted that TODO entry, since it looks like this optimization
isn't worth a big effort.  Computers are so fast nowadays that Emacs
Lisp code hardly needs speeding up.

I only regret that you had to spend time on an optimization that turns
out not to be fruitful.  Thank you for working on it.

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

* Re: Compiling byte code to native
  2004-06-02 22:56 ` Richard Stallman
@ 2004-06-03 10:32   ` Matthew Mundell
  0 siblings, 0 replies; 7+ messages in thread
From: Matthew Mundell @ 2004-06-03 10:32 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> I simply deleted that TODO entry, since it looks like this optimization
> isn't worth a big effort.  Computers are so fast nowadays that Emacs
> Lisp code hardly needs speeding up.

The goal of the entry may also have been to ease the development of
Emacs' internals by introducing Elisp primitives.  Dave Love added the
entry.

> I only regret that you had to spend time on an optimization that turns
> out not to be fruitful.  Thank you for working on it.

Pleasure.  It was by choice, and well worth it for the experience.

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

end of thread, other threads:[~2004-06-03 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-02 11:43 Compiling byte code to native Matthew Mundell
2004-06-02 14:22 ` Stefan Monnier
2004-06-02 16:30   ` Matthew Mundell
2004-06-02 17:04     ` Stefan Monnier
2004-06-02 18:05       ` Matthew Mundell
2004-06-02 22:56 ` Richard Stallman
2004-06-03 10:32   ` Matthew Mundell

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