develooper Front page | perl.perl5.porters | Postings from July 2011

Re: Freeing temps on sub exit

Thread Previous
Father Chrysostomos
July 3, 2011 13:19
Re: Freeing temps on sub exit
Message ID:

On Jun 26, 2011, at 1:29 PM, Craig A. Berry wrote:

> On Sun, Jun 26, 2011 at 2:38 PM, Father Chrysostomos <> wrote:
>>        Message-Id: <>
>>    p4raw-id: //depot/perl@1187
>> (Commit 959e367355 added the refcnt tricks to prevent things from being freed prematurely.)
>> doesn’t have that message, so I can’t find out the reasoning behind it
> See <>.

Thank you.

Ilya Zakharevich wrote:
> The following patch makes it possible to code recursive subroutines in
> Perl.  As Ed noted a year ago, it has almost no impact until you hit
> the size of your core and start swapping.
> (A year ago): With it applied, my lowly SPARC4 (110MHz) could finish
> 	./perl -le 'sub fib {return 1 if $_[0] <=1; fib($_[0]-1)+fib($_[0]-2)} print scalar fib(shift)' 31
> in just 10 minutes (549.93u 0.17s 10:03.16 91.2%).
> Note that the speedup is no more than 20% when you compare the patched
> version and the unpatched one, but the current Perl just cannot do a
> massive "tailish" recursion like the above one: it runs out of memory,
> since temporaries are not freed until the last moment.
> All the tests pass,
> Ilya

OK, it seems to me that recursive calls are likely to get much deeper than calls to different subs (unless there are 10000 different subs calling each other), so that’s why this only needs to apply to recursive calls.

So is there any reason lvalue subs should not do the same?

In fact, would it cause any noticeable slowdown to free temps in pp_leavesub regardless of recursion?

Also, why does freeing temps in pp_leavesub only apply to scalar context? Doesn’t the same problem Ilya mentioned apply to list context as well?

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About