[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is lexical binding so slow?

From: Stefan Monnier
Subject: Re: Why is lexical binding so slow?
Date: Sun, 02 Jul 2017 14:36:05 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]