emacs-devel
[Top][All Lists]
Advanced

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

Re: named-let


From: Stefan Monnier
Subject: Re: named-let
Date: Wed, 20 Jan 2021 14:44:56 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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




reply via email to

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