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

Re: [perl #82110] Still "keys" performance regression between 5.10.1and 5.12.3-RC1

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
March 10, 2011 09:04
Subject:
Re: [perl #82110] Still "keys" performance regression between 5.10.1and 5.12.3-RC1
Message ID:
20110310170427.GD2827@iabyn.com
On Sun, Feb 06, 2011 at 01:07:25PM -0800, Father Chrysostomos via RT wrote:
> On Tue Jan 18 06:53:20 2011, davem wrote:
> > On Sun, Jan 16, 2011 at 01:28:11PM -0800, Father Chrysostomos via RT
> wrote:
> > > An expression like ‘my @array = ...’ might also reference @array on the
> > > right hand side (if named subroutine closes over @array and its return
> > > value is on the rhs), so the no-common-vars optimisation is disabled for
> > > ‘my @array =’.
> > 
> > But we should be able to tell whether the lexical is closed over by its
> > reference count:
> > 
> > $ p -MDevel::Peek -we'my $x; Dump $x'
> > ALLOCATED at -e:1 for padsv (parent 0x0); serial 1763
> > SV = NULL(0x0) at 0x2171f80
> >   REFCNT = 1
> >   FLAGS = (PADMY)
> > 
> > $ p -MDevel::Peek -we'my $x; Dump $x; sub f {$x+1}'
> > ALLOCATED at -e:1 for padsv (parent 0x0); serial 1763
> > SV = NULL(0x0) at 0x283ef90
> >   REFCNT = 2
> >   FLAGS = (PADMY)
> 
> At compile time, the OPpASSIGN_COMMON flag is set when the list
> assignment is compiled. If the list assignment comes before the
> subroutine that closes over the lexical, it’s not possible to know at
> that time.
> It’s not possible to use a reference count in pp_aassign, either,
> because the stack is not reference-counted. (I tried that and got an
> incredible speed-up, but ($a,$b)=($b,$a) stopped working.)

And thinking further, you can get this behaviour without a closure too:

    my $r;
  again:
    my @x = @$r; # *** common assignment on 2nd attempt!
    @x = (1,2,3);
    $r = \@x;
    goto again unless $i++;

So I think this assignment is correctly pessimised, and shouldn't
be regarded as a bug.

I'll close the ticket.




-- 
But Pity stayed his hand. "It's a pity I've run out of bullets",
he thought. -- "Bored of the Rings"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About