Front page | perl.perl5.porters |
Postings from October 2014
Re: Single-item padrange?
Thread Previous
|
Thread Next
From:
Father Chrysostomos
Date:
October 18, 2014 23:28
Subject:
Re: Single-item padrange?
Message ID:
20141018232824.26150.qmail@lists-nntp.develooper.com
Steffen Mueller wrote:
> On 10/18/2014 07:06 PM, Father Chrysostomos wrote:
> > Steffen Mueller wrote:
> >> On 10/18/2014 06:56 AM, Father Chrysostomos wrote:
> >>> $ time ./miniperl -e 'for(1..20000000){() = (0,my($b,$c))}'
> >>
> >> Do you have any idea if this might be also relevant to code that's not
> >> completely contrived?
> >
> > No, not in blead. (Nor can I think of a non-contrived example where
> > your list+pushmark-in-list-context optimisation helps. If you could
> > provide one, that would help put things in perspective.)
>
> Examples: Slices, certain map expressions (if they return more than one
> element).
All right, then:
$ perl5.18.3 -MO=Concise -e 'my($a,$b); @a[$a,$b]'
b <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
- <@> list vKP ->4
3 <0> padrange[$a:1,2; $b:1,2] vM/LVINTRO,2 ->4
- <0> padsv[$a:1,2] vM/LVINTRO ->-
- <0> padsv[$b:1,2] vM/LVINTRO ->-
4 <;> nextstate(main 2 -e:1) v:{ ->5
a <@> aslice vK ->b
5 <0> pushmark s ->6
7 <@> list lK ->8
6 <0> padrange[$a:1,2; $b:1,2] l/2 ->7
- <0> padsv[$a:1,2] l ->-
- <0> padsv[$b:1,2] l ->7
9 <1> rv2av[t3] sKR/1 ->a
8 <$> gv(*a) s ->9
-e syntax OK
$ perl5.20.1 -MO=Concise -e 'my($a,$b); @a[$a,$b]'
b <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
- <@> list vKP ->4
3 <0> padrange[$a:1,2; $b:1,2] vM/LVINTRO,2 ->4
- <0> padsv[$a:1,2] vM/LVINTRO ->-
- <0> padsv[$b:1,2] vM/LVINTRO ->-
4 <;> nextstate(main 2 -e:1) v:{ ->5
a <@> aslice vK ->b
5 <0> pushmark s ->6
- <1> ex-list lK ->8
- <0> ex-pushmark s ->6
6 <0> padsv[$a:1,2] l ->7
7 <0> padsv[$b:1,2] l ->8
9 <1> rv2av[t3] sKR/1 ->a
8 <$> gv(*a) s ->9
-e syntax OK
Notice the kids of the aslice op.
If I try timing it like this:
$ time ./miniperl -e 'my($a,$b); for(1..10000000) { @a[$a,$b] }'
it's 5% slower with padrange, but that might just be noise. What
makes this confusing is that it is the same op sequence that differs
in both one-liners, depending on which optimisation is active: pad-
range+list vs padsv+padsv.
In fact, in the case of aslice, we really don't need to create a list
op to begin with, but it does make deparsing easier.
Now, if we null the *first* pushmark, not the second, then our
pushmark padsv padsv
or
pushmark padrange list
becomes:
padrange
and the result is faster than 5.18 or 5.20.
I wonder whether all other legitimate (non-contrived) cases of
list+pushmark could be simplified similarly.
I also wonder why padrange insists that op_next be equal to
op_sibling. The B overlay feature seems to complicate things, IMO.
We should be able to optimise this with padrange:
1 pushmark
- ex-list
- ex-pushmark
2 padsv
3 padsv
Thread Previous
|
Thread Next