From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Lexical binding doesn't seem to be faster?
Date: Fri, 08 Mar 2019 08:53:32 -0500 [thread overview]
Message-ID: <jwv36nxbhxv.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 20190308083055.GA20901@tuxteam.de
>> FWIW, the usual case where lexical-binding leads to bigger&slower code
>> is when you pass a lambda-expression to another function and that
>> lambda-expression has free variables (in the lexical-binding case, it
>> requires building a closure which is rather costly currently, whereas in
>> the dynamic-binding case it relies on the dynamic-scoping instead).
> Let's see if I got that right: in those cases, the code would (most
> probably!) behave differently depending on the binding regime (lexical
> vs dynamic), so it would be doing quite different things in each case?
Actually, in most such cases the code behaves identically in the end,
but it gets there in a different way (so yes, in some cases it does
behave differently).
E.g.
(let ((buf (current-buffer)))
[...]
(with-temp-buffer
(mapcar (lambda (x)
(with-current-buffer buf ...))
...))
[...])
The end result will most likely be the same regardless which binding
style is used, but the way to find the value of `buf` from within the
lambda is different in the two cases.
The difference becomes apparent if you do
(advice-add 'mapcar :around
(lambda (&rest orig-call)
(let ((buf 42)) (apply orig-call))))
since in this case dynamic-binding will cause your `with-current-buffer`
to try and use buffer 42 and signal an error (because of the name
conflict, aka "variable capture"), whereas lexical-binding
will be unaffected.
Stefan
next prev parent reply other threads:[~2019-03-08 13:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 23:36 Lexical binding doesn't seem to be faster? Hi-Angel
2019-03-08 5:39 ` Stefan Monnier
2019-03-08 8:30 ` tomas
2019-03-08 13:53 ` Stefan Monnier [this message]
2019-03-09 8:21 ` tomas
2019-03-08 13:33 ` Hi-Angel
2019-03-09 15:06 ` Stefan Monnier
2019-03-10 15:16 ` Hi-Angel
2019-03-10 16:14 ` Hi-Angel
2019-03-10 18:07 ` Stefan Monnier
2019-03-10 18:47 ` Hi-Angel
2019-03-10 18:59 ` Stefan Monnier
2019-03-10 19:53 ` Hi-Angel
2019-03-10 20:48 ` Stefan Monnier
2019-03-10 21:22 ` Hi-Angel
2019-03-11 19:16 ` Hi-Angel
2019-03-11 19:26 ` Stefan Monnier
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv36nxbhxv.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@gnu.org \
/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 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.