unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* "simplifications"
@ 2007-11-19 10:46 David Kastrup
  2007-11-19 10:56 ` "simplifications" Juanma Barranquero
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: David Kastrup @ 2007-11-19 10:46 UTC (permalink / raw)
  To: emacs-devel; +Cc: lekktu


Hi, I've seen the following:

Author: Juanma Barranquero <lekktu@gmail.com>  2007-11-17 03:50:37
Committer: Juanma Barranquero <lekktu@gmail.com>  2007-11-17 03:50:37
Parent: 1797ed583c1d6224dbe93db681b112a9b0278358 ((backquote): Improve argument/docstring consistency.)
Child:  034e6631c9aab6db046645510214df80e67c29d4 (*** empty log message ***)
Branches: master, remotes/origin/master, remotes/origin/origin
Follows: merge-multi-tty-to-trunk
Precedes: 

    (ring-size, ring-p, ring-insert, ring-length, ring-empty-p): Use c[ad]dr.
    (ring-plus1): Use `1+'.
    (ring-minus1): Use `zerop'.
    (ring-remove): Use c[ad]dr.  Use `when'.
    (ring-copy): Use c[ad]dr.  Use `let', not `let*'.
    (ring-ref): Use `let', not `let*'.
    (ring-insert-at-beginning): Use c[ad]dr.  Doc fix.
    (ring-insert+extend): Use c[ad]dr.  Fix typo in docstring.
    (ring-member): Simplify.  Doc fix.
    (ring-convert-sequence-to-ring): Simplify.


Could people, before introducing such "optimizations", check the
bytecode?

(defun xxx (x) (cadr x))
generates
byte code for xxx:
  args: (x)
0	varref	  x
1	dup	  
2	varbind	  x
3	cdr	  
4	car	  
5	unbind	  1
6	return	  

while
(defun xxx (x) (car (cdr x)))
generates
byte code for xxx:
  args: (x)
0	varref	  x
1	cdr	  
2	car	  
3	return	  

The former is _quite_ less efficient, so it is not a hot idea to use
it for data access primitives like the ring functions.

Personally, I think that we should make the byte compiler optimize the
unnecessary binding away.  But until that is the case, please don't
gratuitously replace (car (cdr ...)) with (cadr ...).

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 10:46 "simplifications" David Kastrup
@ 2007-11-19 10:56 ` Juanma Barranquero
  2007-11-19 15:11   ` "simplifications" Stefan Monnier
  2007-11-19 11:02 ` "simplifications" Juanma Barranquero
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 10:56 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

On Nov 19, 2007 11:46 AM, David Kastrup <dak@gnu.org> wrote:

> Could people, before introducing such "optimizations", check the
> bytecode?

Some functions of ring.el already used c??r before my change. etc.

> The former is _quite_ less efficient, so it is not a hot idea to use
> it for data access primitives like the ring functions.

Out of idle curiosity, I'd be really interested in knowing about uses
of ring.el where that difference is going to be significant (i.e.,
we're speaking perhaps of thousands of ring function calls per
second?).

> Personally, I think that we should make the byte compiler optimize the
> unnecessary binding away.  But until that is the case, please don't
> gratuitously replace (car (cdr ...)) with (cadr ...).

I don't usually do it gratuitously, or I would've done it in a lot of
places. I stumbled upon it, and certainly having code chock-full of

 (let ((hd (car (car ...)))
        (ln (car ...))
        (vec (cdr (cdr ...))))

is not my idea of fun, or legible, or maintainable, or... you pick the
word. Not that c??r is much of an improvement; we should be able to
define accesor functions in the package

 (defsubst ring--vec (ring)
    (cdr (cdr ring)))

and have the byte-compiler optimize them away.

So, IMO, instead of bringing back the pain, let's enhance the byte-optimizer.

But of course, you can revert the change if you dislike it that much.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 10:46 "simplifications" David Kastrup
  2007-11-19 10:56 ` "simplifications" Juanma Barranquero
@ 2007-11-19 11:02 ` Juanma Barranquero
  2007-11-19 11:33 ` "simplifications" Miles Bader
  2007-11-20  3:59 ` "simplifications" Richard Stallman
  3 siblings, 0 replies; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 11:02 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

Two additional comments, BTW:

> Could people, before introducing such "optimizations", check the
> bytecode?

I didn't write "optimization" anywhere in the ChangeLog, because I was
not worried about optimization.

If you're gonna revert the change, perhaps you'll want also revert the
one to ring-member. My version, with catch, is a lot cleaner IMO, but
in my extremely informal tests (which I did before commiting) it was
about 1,5% slower. I had to go to the hundreds of thousands of
ring-member invocations to see the difference, but perhaps that's very
significant for you.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 10:46 "simplifications" David Kastrup
  2007-11-19 10:56 ` "simplifications" Juanma Barranquero
  2007-11-19 11:02 ` "simplifications" Juanma Barranquero
@ 2007-11-19 11:33 ` Miles Bader
  2007-11-19 11:57   ` "simplifications" David Kastrup
  2007-11-20  3:59 ` "simplifications" Richard Stallman
  3 siblings, 1 reply; 26+ messages in thread
From: Miles Bader @ 2007-11-19 11:33 UTC (permalink / raw)
  To: David Kastrup; +Cc: lekktu, emacs-devel

David Kastrup <dak@gnu.org> writes:
> Personally, I think that we should make the byte compiler optimize the
> unnecessary binding away.

It'd be nice if it did, though you need to analyze the function to make
sure there are no hidden uses of that binding; in particular, you need
to know if any functions called inside the defsubst might use the
dynamic binding of the defsubst's args.

[I personally think that's a bit silly, and that it would be enough to
just define defsubst as not guaranteeing dynamic bindings of its args,
but as a recall, this has been discussed before, and the current
behavior declared necessary...]

This is one area where lexical binding makes things cheaper:

   ;; -*- lexical-binding: t -*-
   (defsubst lcadr (arg) (car (cdr arg)))
   (defun xxx (x) (lcadr x))

=>

   byte code for xxx:
     args: (x)
    interactive: nil
   0	dup	  
   1	cdr	  
   2	car	  
   3	return	  

The "dup" is because stack slot 0 is where argument "x" is kept.
[Since x is only used once, the dup is unnecessary here, but it's
certainly cheaper than varref+varbind.]

-Miles
-- 
80% of success is just showing up.  --Woody Allen

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 11:33 ` "simplifications" Miles Bader
@ 2007-11-19 11:57   ` David Kastrup
  2007-11-19 12:08     ` "simplifications" Juanma Barranquero
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2007-11-19 11:57 UTC (permalink / raw)
  To: Miles Bader; +Cc: lekktu, emacs-devel

Miles Bader <miles.bader@necel.com> writes:

> David Kastrup <dak@gnu.org> writes:
>> Personally, I think that we should make the byte compiler optimize the
>> unnecessary binding away.
>
> It'd be nice if it did, though you need to analyze the function to make
> sure there are no hidden uses of that binding; in particular, you need
> to know if any functions called inside the defsubst might use the
> dynamic binding of the defsubst's args.
>
> [I personally think that's a bit silly, and that it would be enough to
> just define defsubst as not guaranteeing dynamic bindings of its args,
> but as a recall, this has been discussed before, and the current
> behavior declared necessary...]

My recollection was rather that optimizing such cases (for a suitable
definition of "such") was deemed a good idea, but too invasive for the
Emacs 22 release schedule.

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 11:57   ` "simplifications" David Kastrup
@ 2007-11-19 12:08     ` Juanma Barranquero
  2007-11-19 12:21       ` "simplifications" David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 12:08 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel, Miles Bader

On Nov 19, 2007 12:57 PM, David Kastrup <dak@gnu.org> wrote:

> My recollection was rather that optimizing such cases (for a suitable
> definition of "such") was deemed a good idea, but too invasive for the
> Emacs 22 release schedule.

FWIW, my c??r changes to ring.el were commited only to the trunk.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 12:08     ` "simplifications" Juanma Barranquero
@ 2007-11-19 12:21       ` David Kastrup
  2007-11-19 12:32         ` "simplifications" Juanma Barranquero
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2007-11-19 12:21 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel, Miles Bader

"Juanma Barranquero" <lekktu@gmail.com> writes:

> On Nov 19, 2007 12:57 PM, David Kastrup <dak@gnu.org> wrote:
>
>> My recollection was rather that optimizing such cases (for a suitable
>> definition of "such") was deemed a good idea, but too invasive for the
>> Emacs 22 release schedule.
>
> FWIW, my c??r changes to ring.el were commited only to the trunk.

I was not suggesting reverting the changes.  It is not important
enough for that sort of back-and-forth changing.  On the other hand,
as long as it degrades code quality, I'd prefer people to refrain from
doing large-scale "cleanups" or "simplifications" of that kind.
Before we are starting a trend here, it would be nice if the
optimizations making such changes not have an impact on efficiency
would be in place.

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 12:21       ` "simplifications" David Kastrup
@ 2007-11-19 12:32         ` Juanma Barranquero
  2007-11-19 12:49           ` "simplifications" David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 12:32 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel, Miles Bader

On Nov 19, 2007 1:21 PM, David Kastrup <dak@gnu.org> wrote:

> On the other hand,
> as long as it degrades code quality

"Code quality" is an ambiguous metric, unless you define it. I suppose
you're using some variant of the "code quality = efficiency"
equivalence. Obviously I wasn't. That does not mean that I didn't
think of efficiency (I did, or I wouldn't have done measurements of
ring-member's speed). Though I agree that currently (car (cdr x)) is
faster than (cadr x), I still don't see how that will affect much to
clients of ring.el unless they're doing a quite performance-oriented
use of it. OTOH, code is a bit more readable now IMHO.

> I'd prefer people to refrain from
> doing large-scale "cleanups" or "simplifications" of that kind.

That's about a dozen trivial changes in a package with 165 non-empty,
non-comment lines. Perhaps we should previously agree also in the
definition of "large scale".

> Before we are starting a trend here, it would be nice if the
> optimizations making such changes not have an impact on efficiency
> would be in place.

With this, I agree. You see, I was sure we would find some common
ground after all...

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 12:32         ` "simplifications" Juanma Barranquero
@ 2007-11-19 12:49           ` David Kastrup
  2007-11-19 12:54             ` "simplifications" Juanma Barranquero
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2007-11-19 12:49 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel, Miles Bader

"Juanma Barranquero" <lekktu@gmail.com> writes:

> On Nov 19, 2007 1:21 PM, David Kastrup <dak@gnu.org> wrote:
>
>> On the other hand,
>> as long as it degrades code quality
>
> "Code quality" is an ambiguous metric, unless you define it. I suppose
> you're using some variant of the "code quality = efficiency"
> equivalence. Obviously I wasn't. That does not mean that I didn't
> think of efficiency (I did, or I wouldn't have done measurements of
> ring-member's speed). Though I agree that currently (car (cdr x)) is
> faster than (cadr x), I still don't see how that will affect much to
> clients of ring.el unless they're doing a quite performance-oriented
> use of it. OTOH, code is a bit more readable now IMHO.
>
>> I'd prefer people to refrain from
>> doing large-scale "cleanups" or "simplifications" of that kind.
>
> That's about a dozen trivial changes in a package with 165 non-empty,
> non-comment lines. Perhaps we should previously agree also in the
> definition of "large scale".

I am afraid that you are really too eager to interpret my mails as a
personal critique of you and this particular change.  Again: I don't
think this particular case nearly important or relevant enough to
warrant reverting those changes.  But it is not the first such change
I see, and I would prefer to see changes in the byte compiler that
would make such changes a no-brainer, where one does not have to weigh
code efficiency vs. readability.

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 12:49           ` "simplifications" David Kastrup
@ 2007-11-19 12:54             ` Juanma Barranquero
  0 siblings, 0 replies; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 12:54 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel, Miles Bader

On Nov 19, 2007 1:49 PM, David Kastrup <dak@gnu.org> wrote:

> I am afraid that you are really too eager to interpret my mails as a
> personal critique of you and this particular change.

I ask you about definitions, and suddenly I'm "eager to interpret
[...] emails as a personal critique". Curious.

> But it is not the first such change
> I see, and I would prefer to see changes in the byte compiler that
> would make such changes a no-brainer, where one does not have to weigh
> code efficiency vs. readability.

Then perhaps these kinds of changes, in the trunk, will be useful by
furthering the relevance of the issue.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 10:56 ` "simplifications" Juanma Barranquero
@ 2007-11-19 15:11   ` Stefan Monnier
  2007-11-19 15:19     ` "simplifications" David Kastrup
  2007-11-19 15:39     ` "simplifications" Juanma Barranquero
  0 siblings, 2 replies; 26+ messages in thread
From: Stefan Monnier @ 2007-11-19 15:11 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

> is not my idea of fun, or legible, or maintainable, or... you pick the
> word. Not that c??r is much of an improvement; we should be able to
> define accesor functions in the package

>  (defsubst ring--vec (ring)
>     (cdr (cdr ring)))

> and have the byte-compiler optimize them away.

1 - if you use defsubst* the byte-code will look good.
2 - you can use defstruct to get all that and more.
3 - I don't think it's worth the trouble to make the byte-optimizer more
    complex for such little benefit.  If you want to improve it, use the
    lexbind branch: it's a much saner starting point.


        Stefan "whose local Emacs hacks include some byte-optimizer
                improvement which does manage to optimize `cadr' but it's too
                much work works with too many limitations and on top of
                that, it's not even clear that the optimization is
                always correct: it doesn't account for the case where
                you do
                (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
                in which case the optimization is not semantics preserving"

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:11   ` "simplifications" Stefan Monnier
@ 2007-11-19 15:19     ` David Kastrup
  2007-11-19 15:39     ` "simplifications" Juanma Barranquero
  1 sibling, 0 replies; 26+ messages in thread
From: David Kastrup @ 2007-11-19 15:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Juanma Barranquero, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> is not my idea of fun, or legible, or maintainable, or... you pick the
>> word. Not that c??r is much of an improvement; we should be able to
>> define accesor functions in the package
>
>>  (defsubst ring--vec (ring)
>>     (cdr (cdr ring)))
>
>> and have the byte-compiler optimize them away.
>
> 1 - if you use defsubst* the byte-code will look good.
> 2 - you can use defstruct to get all that and more.
> 3 - I don't think it's worth the trouble to make the byte-optimizer more
>     complex for such little benefit.  If you want to improve it, use the
>     lexbind branch: it's a much saner starting point.
>
>
>         Stefan "whose local Emacs hacks include some byte-optimizer
>                 improvement which does manage to optimize `cadr' but it's too
>                 much work works with too many limitations and on top of
>                 that, it's not even clear that the optimization is
>                 always correct: it doesn't account for the case where
>                 you do
>                 (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
>                 in which case the optimization is not semantics preserving"

defsubst is an advanced construct.  I think it is reasonable to give
fewer guarantees about its operation than we do for defun.

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:11   ` "simplifications" Stefan Monnier
  2007-11-19 15:19     ` "simplifications" David Kastrup
@ 2007-11-19 15:39     ` Juanma Barranquero
  2007-11-19 15:44       ` "simplifications" Stefan Monnier
  1 sibling, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 15:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Nov 19, 2007 4:11 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> 1 - if you use defsubst* the byte-code will look good.

Nice. Thanks!

> 2 - you can use defstruct to get all that and more.

Yes. It's not my code; it it were, I would be using defstruct. I'm a
big Common Lisp fan.

> 3 - I don't think it's worth the trouble to make the byte-optimizer more
>     complex for such little benefit.  If you want to improve it, use the
>     lexbind branch: it's a much saner starting point.

Isn't that branch supposed to be merged back someday?

> it doesn't account for the case where
> you do
> (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
> in which case the optimization is not semantics preserving"

And I'n not sure it should... I think I agree with David here: if
you're using defsubst to optimize, you should expect some gotchas.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:39     ` "simplifications" Juanma Barranquero
@ 2007-11-19 15:44       ` Stefan Monnier
  2007-11-19 15:47         ` "simplifications" Juanma Barranquero
                           ` (2 more replies)
  0 siblings, 3 replies; 26+ messages in thread
From: Stefan Monnier @ 2007-11-19 15:44 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

>> it doesn't account for the case where
>> you do
>> (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
>> in which case the optimization is not semantics preserving"

> And I'n not sure it should... I think I agree with David here: if
> you're using defsubst to optimize, you should expect some gotchas.

Well, my optimization is not specific to defsubst, so it will also
remove the let-binding in:

   (let ((debug-on-error t))
     (car (car (cdr x))))


In any case, if you want a "fast and loose" defsubst, it's there already
under the name defsubst*.


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:44       ` "simplifications" Stefan Monnier
@ 2007-11-19 15:47         ` Juanma Barranquero
  2007-11-19 15:58           ` "simplifications" Stefan Monnier
  2007-11-19 16:02         ` "simplifications" David Kastrup
  2007-11-20  3:59         ` "simplifications" Richard Stallman
  2 siblings, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 15:47 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Nov 19, 2007 4:44 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Well, my optimization is not specific to defsubst, so it will also
> remove the let-binding in:
>
>    (let ((debug-on-error t))
>      (car (car (cdr x))))

Why? There can be no dynamic bindings under that optimization?

> In any case, if you want a "fast and loose" defsubst, it's there already
> under the name defsubst*.

I'll remember it. Thanks again.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:47         ` "simplifications" Juanma Barranquero
@ 2007-11-19 15:58           ` Stefan Monnier
  2007-11-19 16:08             ` "simplifications" Juanma Barranquero
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2007-11-19 15:58 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

>> Well, my optimization is not specific to defsubst, so it will also
>> remove the let-binding in:
>> 
>> (let ((debug-on-error t))
>> (car (car (cdr x))))

> Why? There can be no dynamic bindings under that optimization?

Of course, there can, but it knows about primitives that don't use any
dynamically bound variables.  Oh well... except for those funny ones
like debug-on-error which are used virtually everywhere.


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:44       ` "simplifications" Stefan Monnier
  2007-11-19 15:47         ` "simplifications" Juanma Barranquero
@ 2007-11-19 16:02         ` David Kastrup
  2007-11-19 16:05           ` "simplifications" Juanma Barranquero
  2007-11-20  3:59         ` "simplifications" Richard Stallman
  2 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2007-11-19 16:02 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Juanma Barranquero, emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>> it doesn't account for the case where
>>> you do
>>> (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
>>> in which case the optimization is not semantics preserving"
>
>> And I'n not sure it should... I think I agree with David here: if
>> you're using defsubst to optimize, you should expect some gotchas.
>
> Well, my optimization is not specific to defsubst, so it will also
> remove the let-binding in:
>
>    (let ((debug-on-error t))
>      (car (car (cdr x))))
>
>
> In any case, if you want a "fast and loose" defsubst, it's there already
> under the name defsubst*.

For a suitable value of "there":

(describe-function 'defsubst*)
Debugger entered--Lisp error: (void-function defsubst*)
  describe-function-1(defsubst*)
  describe-function(defsubst*)
  eval((describe-function (quote defsubst*)))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp)

-- 
David Kastrup

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 16:02         ` "simplifications" David Kastrup
@ 2007-11-19 16:05           ` Juanma Barranquero
  0 siblings, 0 replies; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 16:05 UTC (permalink / raw)
  To: David Kastrup; +Cc: Stefan Monnier, emacs-devel

On Nov 19, 2007 5:02 PM, David Kastrup <dak@gnu.org> wrote:

> For a suitable value of "there":

It's an (eval-when-compile (require 'cl)) away, of which there are
186+ in the lisp/* tree.

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:58           ` "simplifications" Stefan Monnier
@ 2007-11-19 16:08             ` Juanma Barranquero
  2007-11-19 18:46               ` "simplifications" Stefan Monnier
  0 siblings, 1 reply; 26+ messages in thread
From: Juanma Barranquero @ 2007-11-19 16:08 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On Nov 19, 2007 4:58 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> Of course, there can, but it knows about primitives that don't use any
> dynamically bound variables.  Oh well... except for those funny ones
> like debug-on-error which are used virtually everywhere.

I'm absolutely sure I'm asking something really obvious, but, why
wouldn't simply work to have a list of dynamic variables whose
bindings Just Can Not be optimized away?

             Juanma

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 16:08             ` "simplifications" Juanma Barranquero
@ 2007-11-19 18:46               ` Stefan Monnier
  0 siblings, 0 replies; 26+ messages in thread
From: Stefan Monnier @ 2007-11-19 18:46 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: emacs-devel

>> Of course, there can, but it knows about primitives that don't use any
>> dynamically bound variables.  Oh well... except for those funny ones
>> like debug-on-error which are used virtually everywhere.

> I'm absolutely sure I'm asking something really obvious, but, why
> wouldn't simply work to have a list of dynamic variables whose
> bindings Just Can Not be optimized away?

It would probably work.  I just haven't done it, and given my experience
with this optimization, I'm unlikely to ever do it.


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 10:46 "simplifications" David Kastrup
                   ` (2 preceding siblings ...)
  2007-11-19 11:33 ` "simplifications" Miles Bader
@ 2007-11-20  3:59 ` Richard Stallman
  3 siblings, 0 replies; 26+ messages in thread
From: Richard Stallman @ 2007-11-20  3:59 UTC (permalink / raw)
  To: David Kastrup; +Cc: lekktu, emacs-devel

    Personally, I think that we should make the byte compiler optimize the
    unnecessary binding away.  But until that is the case, please don't
    gratuitously replace (car (cdr ...)) with (cadr ...).

Maybe we could improve the handling of defsubst
to recognize that that binding is unnecessary.
To handle simple cases like this, it is enough to scan
the bytecode instructions and see that they don't call
any functions or refer to that variable.

I think the place to do this is in `byte-compile-unfold-lambda'.

Is someone interested?

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-19 15:44       ` "simplifications" Stefan Monnier
  2007-11-19 15:47         ` "simplifications" Juanma Barranquero
  2007-11-19 16:02         ` "simplifications" David Kastrup
@ 2007-11-20  3:59         ` Richard Stallman
  2007-11-20 15:27           ` "simplifications" Stefan Monnier
  2 siblings, 1 reply; 26+ messages in thread
From: Richard Stallman @ 2007-11-20  3:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: lekktu, emacs-devel

    >> it doesn't account for the case where
    >> you do
    >> (defsubst cadr (debug-on-error) (car (cdr debug-on-error)))
    >> in which case the optimization is not semantics preserving"

I think it is fine to treat the args of a defsubst function
in a special way, as long as we document that.  However,
it would be easy enough to turn off the optimization for variables
that are defvar'd.

    Well, my optimization is not specific to defsubst, so it will also
    remove the let-binding in:

       (let ((debug-on-error t))
	 (car (car (cdr x))))

Which optimization is that one?  It too needs something to prevent it
from removing that binding, such as don't remove bindings for
variables that have been defvar'd.

The optimization I suggested would apply to the expansion of defsubst
calls.  So it would not apply to `let' expressions that originate
in other ways.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-20  3:59         ` "simplifications" Richard Stallman
@ 2007-11-20 15:27           ` Stefan Monnier
  2007-11-21 21:37             ` "simplifications" Stephen J. Turnbull
  0 siblings, 1 reply; 26+ messages in thread
From: Stefan Monnier @ 2007-11-20 15:27 UTC (permalink / raw)
  To: rms; +Cc: lekktu, emacs-devel

>     Well, my optimization is not specific to defsubst, so it will also
>     remove the let-binding in:

>        (let ((debug-on-error t))
> 	 (car (car (cdr x))))

> Which optimization is that one?

Some optimization with which I played locally.  I still have it in my
tree, but all I got from it is an understanding that it's not the right
way to approach the problem :-)


        Stefan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-20 15:27           ` "simplifications" Stefan Monnier
@ 2007-11-21 21:37             ` Stephen J. Turnbull
  2007-11-21 21:52               ` "simplifications" David Kastrup
  0 siblings, 1 reply; 26+ messages in thread
From: Stephen J. Turnbull @ 2007-11-21 21:37 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: lekktu, rms, emacs-devel

Stefan Monnier writes:

 > Some optimization with which I played locally.  I still have it in my
 > tree, but all I got from it is an understanding that it's not the right
 > way to approach the problem :-)

What, not even a "stupid T-shirt"?

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-21 21:37             ` "simplifications" Stephen J. Turnbull
@ 2007-11-21 21:52               ` David Kastrup
  2007-11-22  1:34                 ` "simplifications" Stephen J. Turnbull
  0 siblings, 1 reply; 26+ messages in thread
From: David Kastrup @ 2007-11-21 21:52 UTC (permalink / raw)
  To: Stephen J. Turnbull; +Cc: lekktu, emacs-devel, Stefan Monnier, rms

"Stephen J. Turnbull" <stephen@xemacs.org> writes:

> Stefan Monnier writes:
>
>  > Some optimization with which I played locally.  I still have it in my
>  > tree, but all I got from it is an understanding that it's not the right
>  > way to approach the problem :-)
>
> What, not even a "stupid T-shirt"?

Without so much as a binding, it essentially becomes a single thread.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: "simplifications"
  2007-11-21 21:52               ` "simplifications" David Kastrup
@ 2007-11-22  1:34                 ` Stephen J. Turnbull
  0 siblings, 0 replies; 26+ messages in thread
From: Stephen J. Turnbull @ 2007-11-22  1:34 UTC (permalink / raw)
  To: David Kastrup; +Cc: lekktu, Stefan Monnier, rms, emacs-devel

David Kastrup writes:
 > "Stephen J. Turnbull" <stephen@xemacs.org> writes:
 > 
 > > Stefan Monnier writes:
 > >
 > >  > Some optimization with which I played locally.  I still have it in my
 > >  > tree, but all I got from it is an understanding that it's not the right
 > >  > way to approach the problem :-)
 > >
 > > What, not even a "stupid T-shirt"?
 > 
 > Without so much as a binding, it essentially becomes a single thread.

*splutter*

David, you owe me *three* monitor wipes ... 

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2007-11-22  1:34 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-19 10:46 "simplifications" David Kastrup
2007-11-19 10:56 ` "simplifications" Juanma Barranquero
2007-11-19 15:11   ` "simplifications" Stefan Monnier
2007-11-19 15:19     ` "simplifications" David Kastrup
2007-11-19 15:39     ` "simplifications" Juanma Barranquero
2007-11-19 15:44       ` "simplifications" Stefan Monnier
2007-11-19 15:47         ` "simplifications" Juanma Barranquero
2007-11-19 15:58           ` "simplifications" Stefan Monnier
2007-11-19 16:08             ` "simplifications" Juanma Barranquero
2007-11-19 18:46               ` "simplifications" Stefan Monnier
2007-11-19 16:02         ` "simplifications" David Kastrup
2007-11-19 16:05           ` "simplifications" Juanma Barranquero
2007-11-20  3:59         ` "simplifications" Richard Stallman
2007-11-20 15:27           ` "simplifications" Stefan Monnier
2007-11-21 21:37             ` "simplifications" Stephen J. Turnbull
2007-11-21 21:52               ` "simplifications" David Kastrup
2007-11-22  1:34                 ` "simplifications" Stephen J. Turnbull
2007-11-19 11:02 ` "simplifications" Juanma Barranquero
2007-11-19 11:33 ` "simplifications" Miles Bader
2007-11-19 11:57   ` "simplifications" David Kastrup
2007-11-19 12:08     ` "simplifications" Juanma Barranquero
2007-11-19 12:21       ` "simplifications" David Kastrup
2007-11-19 12:32         ` "simplifications" Juanma Barranquero
2007-11-19 12:49           ` "simplifications" David Kastrup
2007-11-19 12:54             ` "simplifications" Juanma Barranquero
2007-11-20  3:59 ` "simplifications" Richard Stallman

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).