all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: rms@gnu.org, emacs-devel@gnu.org
Subject: Re: byte-code optimizations
Date: Tue, 21 Sep 2004 17:05:30 -0400	[thread overview]
Message-ID: <jwvhdpr5oxo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <200409212242.47848.pogonyshev@gmx.net> (Paul Pogonyshev's message of "Tue, 21 Sep 2004 22:42:47 -0200")

>> Unless I have missed some point here, I think your version of the
>> optimization is the better of the two (all else being equal), because
>> it gets directly to the desired result instead of requiring it to be
>> done in two steps.

> It must also be much simpler (though I never saw what Stefan had).

Yes, it's much simpler.  Also my code can break on some bytecode.
More specifically, my code requires that the specpdl stack be unique for any
given point in the byte-code, which is not the case for example if the
bytecode does the equivalent of

        if cond
           varbind X
        endif
        ...blabla...
        if cond
           unbind 1
        endif

AFAIK, my code works for any bytecode coming out of the current bytecode
compiler (barring bugs), but it might break with some other
bytecode compiler.

>> However, there is still the question of whether we should
>> change the standard defsubst to work the way defsubst* does.
> Maybe we can even use `defmacro' for `caar' and friends.  Since
> they evaluate their lone argument only once, there must not be
> any problems, right?

Just think of (mapcar 'caar x)

> If this (or `defsubst*') works, I'll investigate whether this
> byte-code optimization gives any improvement after such a change.

What defsubst* does is treat the argument as a kind of "lexically scoped"
variable, but only in very limited ways.  I.e. the

        (defsubst* caar (x) (car (car x)))

will expand:

        (caar y)  =>  (car (car y))
        (caar (f y)) => (let ((x (f y))) ..cl-gunk.. (car (car x)))

[ The cl-gunk is stuff added by CL for CL such as a `catch' statement. ]
If you ignore the nasty cl-gunk, I think the resulting optimization is
similar to what we get, except it works in a few more cases.
E.g. it'll expand

     (defsubst* foo (x) (symbol-value x))

     (foo y) => (symbol-value y)

whereas our optimization won't be able to do that because it can't assume
a "somewhat lexically scoped" semantics.


        Stefan

  reply	other threads:[~2004-09-21 21:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-18 13:52 byte-code optimizations Paul Pogonyshev
2004-09-18 20:26 ` Stefan
2004-09-19 11:00   ` Richard Stallman
2004-09-19 16:15   ` Paul Pogonyshev
2004-09-21 18:31     ` Richard Stallman
2004-09-22  0:42       ` Paul Pogonyshev
2004-09-21 21:05         ` Stefan Monnier [this message]
2004-09-21 21:15           ` Miles Bader
2004-09-22  3:31             ` Paul Pogonyshev
2004-09-21 22:57               ` Miles Bader
2004-09-22  3:25           ` Paul Pogonyshev
2004-09-22 18:20         ` Richard Stallman
2004-09-23  0:33           ` Paul Pogonyshev
2004-09-18 22:55 ` Richard Stallman

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