unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: named-let
Date: Wed, 20 Jan 2021 14:44:56 -0500	[thread overview]
Message-ID: <jwvr1mf4d6b.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <jwvpn2egaj3.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 08 Jan 2021 20:43:13 -0500")

> The recent discussion around loops motivated me to look a bit further
> into named-let.  It's actually easy to define:

I now added this `named-let` to `subr-x.el`.
Along with it, I installed two additional optimizations to the byte-code
optimizer.  With those optimization, the byte code generated from

    (defun length-named (xs)
      (named-let recurse ((xs xs) (l 0))
        (if xs (recurse (cdr xs) (1+ l)) l)))

is about 33% slower than that generated from:

    (defun length-fast (xs)
      (let ((l 0))
        (while xs (setq l (1+ l)) (setq xs (cdr xs)))
        l))

(for reference, without the tail-call optimization, `length-named` was
about 300% (i.e. 4x) slower, and with TCO but without the recent extra
tweaks, it was about 70% slower; and the native `length` is 15x faster).

The remaining 33% seem harder to reach, tho.  They're 3 extra
instructions: 2 `stack-ref` instructions to copy the two parameters at
the beginning of the loop body, and one `discardN` instruction to drop
those 2 parameters at the end of the loop body.

I guess we can live with those 33% for now: this is a fairly
pathological test where the loop's body does particularly little, so the
loop overhead is magnified.


        Stefan




      parent reply	other threads:[~2021-01-20 19:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-09  1:43 named-let Stefan Monnier
2021-01-09  8:58 ` named-let tomas
2021-01-09 16:01   ` named-let Joost Kremers
2021-01-09 21:48     ` named-let Stefan Monnier
2021-01-09 15:23 ` named-let Tomas Hlavaty
2021-01-09 16:44   ` named-let Stefan Monnier
2021-01-09 17:03     ` named-let Helmut Eller
2021-01-09 18:43       ` named-let Stefan Monnier
2021-01-09 18:47     ` named-let Tomas Hlavaty
2021-01-10 18:49   ` named-let Zhu Zihao
2021-01-11 22:27     ` named-let Tomas Hlavaty
2021-01-11 22:36       ` named-let Stefan Monnier
2021-01-11 22:48         ` named-let Tomas Hlavaty
2021-01-11 22:50         ` named-let Andrea Corallo via Emacs development discussions.
2021-01-11 23:10           ` named-let Stefan Monnier
2021-01-11 23:28             ` named-let Andrea Corallo via Emacs development discussions.
2021-01-11 23:57               ` named-let Stefan Monnier
2021-01-12  9:24                 ` named-let Andrea Corallo via Emacs development discussions.
2021-01-12 18:07                   ` named-let Stefan Monnier
2021-01-12 18:50                     ` named-let Andrea Corallo via Emacs development discussions.
2021-01-12  9:13             ` named-let Helmut Eller
2021-01-13  8:11         ` named-let Zhu Zihao
2021-01-13 14:01           ` named-let Stefan Monnier
2021-01-11 22:40       ` named-let Andrea Corallo via Emacs development discussions.
2021-01-11 22:51         ` named-let Tomas Hlavaty
2021-01-11 23:04           ` named-let Andrea Corallo via Emacs development discussions.
2021-01-12  0:12             ` named-let Tomas Hlavaty
2021-01-20 19:44 ` Stefan Monnier [this message]

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvr1mf4d6b.fsf-monnier+emacs@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 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).