all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Performance of lexical closures in interpreted code? (was Re: Execution speed)
Date: Mon, 20 Mar 2017 08:50:32 -0400	[thread overview]
Message-ID: <jwvmvcgktsv.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: a9f1fc89-c398-aeea-69e7-b58fdf2e2219@orcon.net.nz

> Tangentially, that performance hit on the interpreted recursive
> code with lexical-binding enabled is pretty severe!  From well under
> 2 seconds (with dynamic binding) to well over 4 seconds (with lexical
> binding) in all my results.
> Is this a known/accepted trade-off for the better byte-compiled
> performance?

Yes and no: I consider the performance of interpreted code to be
basically irrelevant, so I haven't paid any attention to it when
introducing the lexical-binding functionality: when performance matters,
the code should be compiled.

> I'm assuming it's to do with overheads of lexical closures.

As you can guess from the above, I don't really know.  But I'd be
surprised if it's the case.  A more likely reason is the handling of the
lexical environment (e.g. all the let-rebinding of the dynamically-scoped
var which holds the lexical environment).

> The output npostavs generates indicates that it's largely (if
> not solely) on account of a vast quantity of garbage collection.
> Perhaps that is all the lexical environments being cleaned up?

Quite likely, yes.

> (Although I would have thought that was a requirement for the
> byte-compiled code as well, so I'm very much guessing.)

The lexical environment is mostly "compiled away".  In the bytecode, new
lexical vars are just pushed on the stack, whereas in interpreted code
a new lexical var means adding a new element to an alist (i.e. 2 `cons`).

> Can that be improved, or is this most likely to remain this way?

Of course it can be improved.  It might take a fair bit of effort, tho
(e.g. I think to be more efficient, you'll likely want to pass the
lexical-env as an additional argument rather than by storing it in
a global (dynamically-scoped) var, but this will require changes to all
the special forms (grep for UNEVALLED)).


        Stefan




  reply	other threads:[~2017-03-20 12:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-19 15:12 Execution speed Stefan Monnier
2017-03-19 15:26 ` Mark Oteiza
2017-03-19 15:32 ` Eli Zaretskii
2017-03-19 16:01 ` Tino Calancha
2017-03-19 16:14 ` Andreas Politz
2017-03-19 16:33 ` Teemu Likonen
2017-03-19 19:09 ` npostavs
2017-03-19 22:49   ` Phil Sainty
2017-03-20 10:36     ` Performance of lexical closures in interpreted code? (was Re: Execution speed) Phil Sainty
2017-03-20 12:50       ` Stefan Monnier [this message]
2017-03-20 13:12         ` Stefan Monnier
2017-03-19 22:30 ` Execution speed Phil Sainty
2017-03-20  9:46 ` Ivan Kanis
2017-03-20 10:46   ` Philippe Vaucher
2017-03-20 14:26 ` Filipp Gunbin

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=jwvmvcgktsv.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@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.