all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Why is lexical binding so slow?
@ 2017-07-02 18:15 Philipp Stephani
  2017-07-02 18:36 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Philipp Stephani @ 2017-07-02 18:15 UTC (permalink / raw)
  To: Emacs developers

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

Hi,

the manual states (
https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html
):
"Lexical binding opens up many more opportunities for optimization, so
programs using it are likely to run faster in future Emacs versions."
However, in practice, at least some libraries are significantly slower with
lexical binding, cf.
https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855.
Why is that? Shouldn't code compiled with lexical binding be at least as
fast as code compiled with dynamic binding?

Philipp

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

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

* Re: Why is lexical binding so slow?
  2017-07-02 18:15 Why is lexical binding so slow? Philipp Stephani
@ 2017-07-02 18:36 ` Stefan Monnier
  2017-12-25 21:20   ` Philipp Stephani
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-07-02 18:36 UTC (permalink / raw)
  To: emacs-devel

> https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855.
> Why is that?

Depends on specifics, so someone would have to investigate.  I remember
discussing a performance problem in js2 with Dmitry a while ago (it
lead to the introduction of new byte-codes controlled by
byte-compile--use-old-handlers).  A minor modification to the source
code eliminated the performance difference between lexbind and dynbind,
and the new handlers bytecodes made the lexbind case slightly
faster (or maybe both cases?), IIRC.

> Shouldn't code compiled with lexical binding be at least as
> fast as code compiled with dynamic binding?

Not necessarily, no.  E.g. when you use `mapcar` and the function
argument has free lexical variables, the lexbind code will have to build
a closure to pass to mapcar.  The access to the lexical vars in the
closure will usually be faster than the corresponding access to those
vars via dynbinding, so if mapcar makes enough calls lexbind can still
be faster, but if mapcar makes few calls, dynbind is faster.


        Stefan




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

* Re: Why is lexical binding so slow?
  2017-07-02 18:36 ` Stefan Monnier
@ 2017-12-25 21:20   ` Philipp Stephani
  2017-12-26  4:49     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Philipp Stephani @ 2017-12-25 21:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

Stefan Monnier <monnier@iro.umontreal.ca> schrieb am So., 2. Juli 2017 um
20:36 Uhr:

> > https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855.
> > Why is that?
>
> Depends on specifics, so someone would have to investigate.


I that case the reason was just a dumb mistake on my part: I ran the
benchmark without byte-compiled files. With byte compilation lexical
binding becomes at least as fast as dynamic binding.


> > Shouldn't code compiled with lexical binding be at least as
> > fast as code compiled with dynamic binding?
>
> Not necessarily, no.  E.g. when you use `mapcar` and the function
> argument has free lexical variables, the lexbind code will have to build
> a closure to pass to mapcar.  The access to the lexical vars in the
> closure will usually be faster than the corresponding access to those
> vars via dynbinding, so if mapcar makes enough calls lexbind can still
> be faster, but if mapcar makes few calls, dynbind is faster.
>
>
Thanks for the explanation.

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

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

* Re: Why is lexical binding so slow?
  2017-12-25 21:20   ` Philipp Stephani
@ 2017-12-26  4:49     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2017-12-26  4:49 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: monnier, emacs-devel

> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Mon, 25 Dec 2017 21:20:23 +0000
> Cc: emacs-devel@gnu.org
> 
> Stefan Monnier <monnier@iro.umontreal.ca> schrieb am So., 2. Juli 2017 um 20:36 Uhr:
> 
>  > https://github.com/mooz/js2-mode/issues/426#issuecomment-312506855.
>  > Why is that?
> 
>  Depends on specifics, so someone would have to investigate. 
> 
> I that case the reason was just a dumb mistake on my part: I ran the benchmark without byte-compiled files.
> With byte compilation lexical binding becomes at least as fast as dynamic binding.

If lexical binding is slow when run with uncompiled code, then our
bootstrap is slower than it could be, because the first several dozen
Lisp files are compiled and loaded with Emacs whose byte compiler and
the rest of the Lisp code have not yet been byte-compiled.



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

end of thread, other threads:[~2017-12-26  4:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-02 18:15 Why is lexical binding so slow? Philipp Stephani
2017-07-02 18:36 ` Stefan Monnier
2017-12-25 21:20   ` Philipp Stephani
2017-12-26  4:49     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.