Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"Whip me. Beat me. Make me maintain AIX." (By Stephan Zielinski)


devel / comp.lang.lisp / Re: Optimizing &rest lists away

SubjectAuthor
* Optimizing &rest lists awayStefan Monnier
+* Re: Optimizing &rest lists awayJeff Barnett
|`* Re: Optimizing &rest lists awayStefan Monnier
| `- Re: Optimizing &rest lists awayJeff Barnett
`* Re: Optimizing &rest lists awayZyni Moë
 +* Re: Optimizing &rest lists awayZyni Moë
 |`* Re: Optimizing &rest lists awayJeff Barnett
 | `- Re: Optimizing &rest lists awayZyni Moë
 `* Re: Optimizing &rest lists awayStefan Monnier
  `* Re: Optimizing &rest lists awayZyni Moë
   `* Re: Optimizing &rest lists awayStefan Monnier
    `* Re: Optimizing &rest lists awayZyni Moë
     `- Re: Optimizing &rest lists awayStefan Monnier

1
Optimizing &rest lists away

<jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16787&group=comp.lang.lisp#16787

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.lang.lisp
Subject: Optimizing &rest lists away
Date: Fri, 14 Jan 2022 13:56:29 -0500
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e3f7820f070efea3265ba3e5a501b1cd";
logging-data="21097"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HEWB7YtZmB1NCxtU3xSCN"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:b05jwYvL64YtwFUgV9AY95UZl3I=
sha1:ko6VtRNRCThqONz11EuoCFK8KxM=
 by: Stefan Monnier - Fri, 14 Jan 2022 18:56 UTC

Does anyone here knows what kind of optimizations are performed by Lisp
compilers to try and avoid allocating lists for the &rest arguments?
I'm thinking especially at cases like

(lambda (&rest args) (do foo) (apply bar args))

-- Stefan

Re: Optimizing &rest lists away

<srslq3$n9e$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16788&group=comp.lang.lisp#16788

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Fri, 14 Jan 2022 13:18:07 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <srslq3$n9e$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 14 Jan 2022 20:18:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="828d09b199410a53e02a2d0cbb240b70";
logging-data="23854"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/wGiHdeXBziG+LPk3Ecs1U3S7laX5rV9w="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:5y6OMWrZNu1kJTAOQpnCrjJyPMI=
In-Reply-To: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
Content-Language: en-US
 by: Jeff Barnett - Fri, 14 Jan 2022 20:18 UTC

On 1/14/2022 11:56 AM, Stefan Monnier wrote:
> Does anyone here knows what kind of optimizations are performed by Lisp
> compilers to try and avoid allocating lists for the &rest arguments?
> I'm thinking especially at cases like
>
> (lambda (&rest args) (do foo) (apply bar args))
I believe that some stack allocate the lists and cdr code them there.
Thus, the actual answer to your question involves storage conventions as
well as compiler optimizations, e.g., can you cdr code on the stack, etc.

I think there are also some words of wisdom or warnings in the Common
Lisp spec about what you can and cannot do (shall and shall not do?)
with rest lists so that theses optimizations are possible.
--
Jeff Barnett

Re: Optimizing &rest lists away

<jwvilumm3c1.fsf-monnier+comp.lang.lisp@gnu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16789&group=comp.lang.lisp#16789

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Fri, 14 Jan 2022 16:15:11 -0500
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <jwvilumm3c1.fsf-monnier+comp.lang.lisp@gnu.org>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<srslq3$n9e$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="e3f7820f070efea3265ba3e5a501b1cd";
logging-data="23644"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lkyE6UMWypFb4eAC4a8qO"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:xVhJRJ5axGa+DT7CYrYBdBuO9c8=
sha1:QsRuJ6vlQorq/0WgiVRmItQNEqE=
 by: Stefan Monnier - Fri, 14 Jan 2022 21:15 UTC

Jeff Barnett [2022-01-14 13:18:07] wrote:
> On 1/14/2022 11:56 AM, Stefan Monnier wrote:
>> Does anyone here knows what kind of optimizations are performed by Lisp
>> compilers to try and avoid allocating lists for the &rest arguments?
>> I'm thinking especially at cases like
>> (lambda (&rest args) (do foo) (apply bar args))
> I believe that some stack allocate the lists and cdr code them there.

Clever, thanks.
I didn't know cdr-coding was still in use.

> Thus, the actual answer to your question involves storage conventions
> as well as compiler optimizations, e.g., can you cdr code on the
> stack, etc.

I guess this falls in the category of those implementations which
don't copy the list when going from `apply` to &rest`.
In ELisp, we've had a "NEWLY-ALLOCATED" semantics from the start, so the
general case is inevitably expensive :-(

> I think there are also some words of wisdom or warnings in the Common Lisp
> spec about what you can and cannot do (shall and shall not do?) with rest
> lists so that theses optimizations are possible.

Do you know of any other discussion around this than "Issue
REST-LIST-ALLOCATION Writeup"?

Stefan

Re: Optimizing &rest lists away

<srt2gh$9p1$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16790&group=comp.lang.lisp#16790

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Fri, 14 Jan 2022 16:54:56 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <srt2gh$9p1$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<srslq3$n9e$1@dont-email.me> <jwvilumm3c1.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 14 Jan 2022 23:54:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2e71ea3db08d6267da2a15770bd99dda";
logging-data="10017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NFkd670sALpMAR9OB8ODl8LbmZpkQnmY="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:aZAlWn7VjlUHun9LVhBl0JPTepk=
In-Reply-To: <jwvilumm3c1.fsf-monnier+comp.lang.lisp@gnu.org>
Content-Language: en-US
 by: Jeff Barnett - Fri, 14 Jan 2022 23:54 UTC

On 1/14/2022 2:15 PM, Stefan Monnier wrote:
> Jeff Barnett [2022-01-14 13:18:07] wrote:
>> On 1/14/2022 11:56 AM, Stefan Monnier wrote:
>>> Does anyone here knows what kind of optimizations are performed by Lisp
>>> compilers to try and avoid allocating lists for the &rest arguments?
>>> I'm thinking especially at cases like
>>> (lambda (&rest args) (do foo) (apply bar args))
>> I believe that some stack allocate the lists and cdr code them there.
>
> Clever, thanks.
> I didn't know cdr-coding was still in use.
>
>> Thus, the actual answer to your question involves storage conventions
>> as well as compiler optimizations, e.g., can you cdr code on the
>> stack, etc.
>
> I guess this falls in the category of those implementations which
> don't copy the list when going from `apply` to &rest`.
> In ELisp, we've had a "NEWLY-ALLOCATED" semantics from the start, so the
> general case is inevitably expensive :-(
>
>> I think there are also some words of wisdom or warnings in the Common Lisp
>> spec about what you can and cannot do (shall and shall not do?) with rest
>> lists so that theses optimizations are possible.
>
> Do you know of any other discussion around this than "Issue
> REST-LIST-ALLOCATION Writeup"?
Unfortunately, I don't. I haven't thought about this in years. But there
are regular contributors here that I'm sure have.
--
Jeff Barnett

Re: Optimizing &rest lists away

<st76dd$cou$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16802&group=comp.lang.lisp#16802

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Sun, 30 Jan 2022 23:19:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <st76dd$cou$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 30 Jan 2022 23:19:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="be8aa77fa0b0ae7aaa2c749b5befe8e8";
logging-data="13086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/b3aRLtBl69rDZRG4ItI3q1XV25R7wGu0="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:nPTQxP3TFPxDtD5T0jjxGmDd63k=
sha1:eV8AX9LEURw7vHfWQbTPaP3UQR0=
 by: Zyni Moë - Sun, 30 Jan 2022 23:19 UTC

Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> Does anyone here knows what kind of optimizations are performed by Lisp
> compilers to try and avoid allocating lists for the &rest arguments?
> I'm thinking especially at cases like
>
> (lambda (&rest args) (do foo) (apply bar args))
>
>

In CL it is allowed (but not required) that &rest lists share with the last
argument to apply. In a case like this what that means is essentially
this:

(let ((x '(1 2))) (apply (lambda (&rest args) (apply (lambda (&rest args)
(eq args x)) args) x))

may return true, as (obviously) may

(let ((x '(1 2))) (apply (lambda (&rest args) (eq args x)) x))

In a case like

(funcall (lambda (&rest args) args) 1 2)

This is not possible and the rest list must be freshly consed.

It is possible to declare that the rest list may be stack allocated:

(funcall (lambda (&rest args) (declare (dynamic-extent args)) ...)1 2)

Would allow args to be stack allocated (and returning it would be an error
in that case).

I doubt any implementations use cdr coding now but perhaps I am wrong.

--
the small snake

Re: Optimizing &rest lists away

<stdunr$23h$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16803&group=comp.lang.lisp#16803

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Wed, 2 Feb 2022 12:51:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <stdunr$23h$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 2 Feb 2022 12:51:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4be8aee71c34a9883ff6936423463b03";
logging-data="2161"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RIX9J4Ct8uUdYE2t18UqEcIb7CT6kMdM="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:lWg7P9AZXNw3GYtXU6wXV7SfRPw=
sha1:D7c7cudEmNzLP8GZdQT/g8cCuCI=
 by: Zyni Moë - Wed, 2 Feb 2022 12:51 UTC

Zyni Moë <no_email@invalid.invalid> wrote:

>
> I doubt any implementations use cdr coding now but perhaps I am wrong.
>

Should have read: 'any stock hardware implementations'

--
the small snake

Re: Optimizing &rest lists away

<steht6$6sq$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16804&group=comp.lang.lisp#16804

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jbb@notatt.com (Jeff Barnett)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Wed, 2 Feb 2022 11:18:11 -0700
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <steht6$6sq$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me> <stdunr$23h$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: base64
Injection-Date: Wed, 2 Feb 2022 18:18:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cb47c2ecafe22d9375860e729706bea8";
logging-data="7066"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/y/I0OpDAntZXZqEFxF9lVuX+XsqrH48="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:fUP9rlmHY8GHbAPobluSxStwhEk=
In-Reply-To: <stdunr$23h$1@dont-email.me>
Content-Language: en-US
 by: Jeff Barnett - Wed, 2 Feb 2022 18:18 UTC

On 2/2/2022 5:51 AM, Zyni Moë wrote:
> Zyni Moë <no_email@invalid.invalid> wrote:
>
>>
>> I doubt any implementations use cdr coding now but perhaps I am wrong.
>>
>
> Should have read: 'any stock hardware implementations'
Actually cdr coding was invented and implemented in several Lisp systems
before there were any special hardware for it. Memory used to be a very
precious resource. Think of tiny memories and no virtually addresses.
Glorious Lisp systems lived and thrived in less space than many people
use for their address books today.
--
Jeff Barnett

Re: Optimizing &rest lists away

<jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16805&group=comp.lang.lisp#16805

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Wed, 02 Feb 2022 22:57:02 -0500
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4d62183953328bb61fb4479aeea92caf";
logging-data="3701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2fWLr2Pi2LM+cDiVVt0wH"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:YqiKsGfcx4gOgfDdY/9t+Jt6aEo=
sha1:crpRNvIvjlq/UjxFlUytDCNzuGs=
 by: Stefan Monnier - Thu, 3 Feb 2022 03:57 UTC

> In CL it is allowed (but not required) that &rest lists share with the last
> argument to apply. In a case like this what that means is essentially
> this:
>
> (let ((x '(1 2))) (apply (lambda (&rest args) (apply (lambda (&rest args)
> (eq args x)) args) x))
>
> may return true, as (obviously) may
>
> (let ((x '(1 2))) (apply (lambda (&rest args) (eq args x)) x))

Right, ELisp hasn't said a word about it, but given that it's created
a fresh list for the last almost 40 years it de-facto guarantees a fresh copy.

> In a case like
>
> (funcall (lambda (&rest args) args) 1 2)

None of those examples are like the one I showed, tho. The trick in my
example is that the &rest argument is only used by passing it further to
`apply`, so whether it's fresh or not doesn't really matter.
Even better if `FCT` is defined as

(lambda (&rest args) (do foo) (apply bar args))

then when we execute

(funcall FCT <blabla>)

it might be possible to avoid allocating a list at all for those
<blabla> arguments and instead passing them on the stack or even in
registers to `bar`.

Stefan

Re: Optimizing &rest lists away

<sthd4f$kv7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16806&group=comp.lang.lisp#16806

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Thu, 3 Feb 2022 20:15:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <sthd4f$kv7$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
<stdunr$23h$1@dont-email.me>
<steht6$6sq$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 3 Feb 2022 20:15:11 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2bae14c53434ce11ca195a31e4c2aed9";
logging-data="21479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3SP9aCKizmCNEQjEUbOMOWliehaJbzUY="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:uiZy1Edep6eIuD787cmslDU2K7U=
sha1:H6Nag6eXle/QG80jXBKuG+euk/I=
 by: Zyni Moë - Thu, 3 Feb 2022 20:15 UTC

Jeff Barnett <jbb@notatt.com> wrote:

> Actually cdr coding was invented and implemented in several Lisp systems
> before there were any special hardware for it. Memory used to be a very
> precious resource. Think of tiny memories and no virtually addresses.
> Glorious Lisp systems lived and thrived in less space than many people
> use for their address books today.

Am aware of that. But those machines were very, very different than modern
ones.

--
the small snake

Re: Optimizing &rest lists away

<sthdh7$nvr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16807&group=comp.lang.lisp#16807

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Thu, 3 Feb 2022 20:22:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sthdh7$nvr$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
<jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 3 Feb 2022 20:22:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2bae14c53434ce11ca195a31e4c2aed9";
logging-data="24571"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oO6srnUtNxEo+FVRxswSettAhrDotwzU="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:IX72or3j39VTj2stC2IN8FoN+6Y=
sha1:VYGyZrg21ZREyXYKqca+/jhFH3E=
 by: Zyni Moë - Thu, 3 Feb 2022 20:22 UTC

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

> None of those examples are like the one I showed, tho. The trick in my
> example is that the &rest argument is only used by passing it further to
> `apply`, so whether it's fresh or not doesn't really matter.
> Even better if `FCT` is defined as
>
> (lambda (&rest args) (do foo) (apply bar args))
>
> then when we execute
>
> (funcall FCT <blabla>)
>
> it might be possible to avoid allocating a list at all for those
> <blabla> arguments and instead passing them on the stack or even in
> registers to `bar`.
>

Unless you know that bar cannot return this list (or place it in any
structure which outlives a call to it) then you cannot do this. If you do
know that, then if you wish to allow bar to be redefined, then you must
then either be willing to recompile its callers or not do this.

If bar is a variable (as it seems to be in your example) that means you
must know this about all the functions to which it may be bound.

So yes, perhaps system which is able to do heroic whole-program analysis
can do this. Sometimes.

--
the small snake

Re: Optimizing &rest lists away

<jwvwniabuql.fsf-monnier+comp.lang.lisp@gnu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16810&group=comp.lang.lisp#16810

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Fri, 04 Feb 2022 09:08:31 -0500
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <jwvwniabuql.fsf-monnier+comp.lang.lisp@gnu.org>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
<jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>
<sthdh7$nvr$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="5fd6114cddeea4c630d960df63efefec";
logging-data="19275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+WF9UmrtrydQCyMxsZHHVc"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:mzd7nC/ga6YXrxt/Kh5ZFp070l0=
sha1:BZkAFOY6QOAr+dehPrs+nPnpof8=
 by: Stefan Monnier - Fri, 4 Feb 2022 14:08 UTC

Zyni Moë [2022-02-03 20:22:00] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> None of those examples are like the one I showed, tho. The trick in my
>> example is that the &rest argument is only used by passing it further to
>> `apply`, so whether it's fresh or not doesn't really matter.
>> Even better if `FCT` is defined as
>>
>> (lambda (&rest args) (do foo) (apply bar args))
>>
>> then when we execute
>>
>> (funcall FCT <blabla>)
>>
>> it might be possible to avoid allocating a list at all for those
>> <blabla> arguments and instead passing them on the stack or even in
>> registers to `bar`.
> Unless you know that bar cannot return this list (or place it in any
> structure which outlives a call to it) then you cannot do this.

I think you misunderstood: the stack and/or registers I refer to are
those used by the normal function call API (whichever it is).

If `bar` itself has an `&rest` arg, then we may need to turn those args
into a list after all, but that'd be part of the normal course of
"calling bar".

More specifically the code would simply end up executing the

(apply bar args)

in the same as way as

(funcall bar <blabla>)

would be processed.

> If you do know that, then if you wish to allow bar to be redefined,
> then you must then either be willing to recompile its callers or not
> do this.

I don't think redefinition of bar would cause any issue since the
optimization should only change the execution until we get to `bar` but not
once we're calling `bar` (unless `bar` itself has that same wrapper-like
property of taking a `&rest` only to pass it to `apply`, in which case
the same optimization would apply again, of course).

> So yes, perhaps system which is able to do heroic whole-program analysis
> can do this. Sometimes.

I think the only analysis needed is to discover that the `args` in the
function is only ever passed to `apply` and hence doesn't need to
represented as an actual list but can be represented in any way we fancy
(as long as `apply` also understands it, obviously). And then try and
make use of that info in `funcall` and `apply`.

Stefan

Re: Optimizing &rest lists away

<stn31n$lhc$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16815&group=comp.lang.lisp#16815

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: no_email@invalid.invalid (Zyni Moë)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Sat, 5 Feb 2022 23:59:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <stn31n$lhc$1@dont-email.me>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
<jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>
<sthdh7$nvr$1@dont-email.me>
<jwvwniabuql.fsf-monnier+comp.lang.lisp@gnu.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 5 Feb 2022 23:59:51 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="65eebf084e6bf45168fbeabe6d63c069";
logging-data="22060"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bQ6hHnvtByMgrGoUFeXLG3Nf8Bd8OMk4="
User-Agent: NewsTap/5.5 (iPad)
Cancel-Lock: sha1:rtbSOsFlyFomhind1x2aAPJbXB8=
sha1:gUt6HWNVh06YEH8tSgc15kZeoO0=
 by: Zyni Moë - Sat, 5 Feb 2022 23:59 UTC

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

>
> I think the only analysis needed is to discover that the `args` in the
> function is only ever passed to `apply` and hence doesn't need to
> represented as an actual list but can be represented in any way we fancy
> (as long as `apply` also understands it, obviously). And then try and
> make use of that info in `funcall` and `apply`.
>

I think what you are saying is that if you can prove some &rest list is
only used in very constrained ways (which may even happen sometimes) you
can stack allocate it because no-one will be able to know you did. Yes.

Also you are free to represent it in linear B, carve into clay tablets, so
long as no-one can tell.

--
the small snake

Re: Optimizing &rest lists away

<jwv4k5c3qib.fsf-monnier+comp.lang.lisp@gnu.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=16816&group=comp.lang.lisp#16816

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: monnier@iro.umontreal.ca (Stefan Monnier)
Newsgroups: comp.lang.lisp
Subject: Re: Optimizing &rest lists away
Date: Sun, 06 Feb 2022 11:33:31 -0500
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <jwv4k5c3qib.fsf-monnier+comp.lang.lisp@gnu.org>
References: <jwvczkuno5e.fsf-monnier+comp.lang.lisp@gnu.org>
<st76dd$cou$1@dont-email.me>
<jwviltw1uef.fsf-monnier+comp.lang.lisp@gnu.org>
<sthdh7$nvr$1@dont-email.me>
<jwvwniabuql.fsf-monnier+comp.lang.lisp@gnu.org>
<stn31n$lhc$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="843bacd76fb34cafa69c44c1444dcab3";
logging-data="2689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IIPkpDdo1MnPsaoXeajXW"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
Cancel-Lock: sha1:sJDLPkRfs97jFJd1gRPAttcaZNY=
sha1:nB7RNfJxFe+DCfMO5eItIt66tJs=
 by: Stefan Monnier - Sun, 6 Feb 2022 16:33 UTC

Zyni Moë [2022-02-05 23:59:51] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> I think the only analysis needed is to discover that the `args` in the
>> function is only ever passed to `apply` and hence doesn't need to
>> represented as an actual list but can be represented in any way we fancy
>> (as long as `apply` also understands it, obviously). And then try and
>> make use of that info in `funcall` and `apply`.
>>
>
> I think what you are saying is that if you can prove some &rest list is
> only used in very constrained ways (which may even happen sometimes) you
> can stack allocate it because no-one will be able to know you did. Yes.
>
> Also you are free to represent it in linear B, carve into clay tablets, so
> long as no-one can tell.

That's right. But the original question is not what is legal w.r.t to
the Common Lisp spec, but "what kind of optimizations are performed by
Lisp compilers" ;-)

Stefan


devel / comp.lang.lisp / Re: Optimizing &rest lists away

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor