Front page | perl.perl5.porters |
Postings from January 2014
[perl #121077] [PATCH] Optimise 'my $x; my $y' into 'my ($x, $y)'
Thread Next
From:
Tony Cook via RT
Date:
January 27, 2014 01:31
Subject:
[perl #121077] [PATCH] Optimise 'my $x; my $y' into 'my ($x, $y)'
Message ID:
rt-4.0.18-10352-1390786283-1001.121077-15-0@perl.org
On Fri Jan 24 15:31:24 2014, alh wrote:
> First pass at optimisation for 'my $x; my $y;' -> 'my ($x, $y)'.
>
> This changes padop -> nextate -> padop -> nexstate into a padrange ->
> nextstate,
> which allows further padrange optimisations to occur.
>
> Brings:
>
> sub { my $x; my $y; return 1; }
>
> Up to speed with:
>
> sub { my ($x, $y); return 1; }
>
> For comparison, here's vanilla blead:
>
> $ blead/bin/perl5.19.9 -MO=Concise,-exec -e 'my $x; my %y; my @z;
> print "hi"'
> 1 <0> enter
> 2 <;> nextstate(main 1 -e:1) v:{
> 3 <0> padsv[$x:1,4] vM/LVINTRO
> 4 <;> nextstate(main 2 -e:1) v:{
> 5 <0> padhv[%y:2,4] vM/LVINTRO
> 6 <;> nextstate(main 3 -e:1) v:{
> 7 <0> padav[@z:3,4] vM/LVINTRO
> 8 <;> nextstate(main 4 -e:1) v:{
> 9 <0> pushmark s
> a <$> const(PV "hi") s
> b <@> print vK
> c <@> leave[1 ref] vKP/REFC
> -e syntax OK
>
> Here's with the patch:
>
> $ padopperl/bin/perl5.19.9 -MO=Concise,-exec -e 'my $x; my %y; my
> @z; print "hi"'
> 1 <0> enter
> 2 <;> nextstate(main 1 -e:1) v:{
> 3 <0> padrange[$x:1,4; %y:2,4; @z:3,4] v/LVINTRO,3
> 4 <;> nextstate(main 4 -e:1) v:{
> 5 <0> pushmark s
> 6 <$> const(PV "hi") s
> 7 <@> print vK
> 8 <@> leave[1 ref] vKP/REFC
> -e syntax OK
>
> And here's vanilla blead with 'my ($x, %y, @z); print "hi"':
>
> $ blead/bin/perl5.19.9 -MO=Concise,-exec -e 'my ($x, %y, @z); print
> "hi"'
> 1 <0> enter
> 2 <;> nextstate(main 1 -e:1) v:{
> 3 <0> padrange[$x:1,2; %y:1,2; @z:1,2] vM/LVINTRO,3
> 4 <;> nextstate(main 2 -e:1) v:{
> 5 <0> pushmark s
> 6 <$> const(PV "hi") s
> 7 <@> print vK
> 8 <@> leave[1 ref] vKP/REFC
> -e syntax OK
>
> There's two differences here:
>
> The ranges of the padops [$x:1,4 ...] vs [$x1,2 ...], though I'm not
> sure that matters.
>
> The flag 'M' (OPf_MOD) on vanilla blead's padrange doesn't show up
> on my patched version.
> I'm not sure if I should be setting this here, how to detect when to
> set it, etc...
>
> Attached are a few files I used to benchmark the changes, and I'm
> mostly happy with the results.
>
> Specifically:
>
> --- blead.txt 2014-01-24 09:06:47.853365045 -0500
> +++ padops.txt 2014-01-24 09:06:54.749364968 -0500
> @@ -1,51 +1,51 @@
> mhorsfall@tworivers:~/perl-1$ time ./perl -Ilib ~/bench.pl
> Benchmark: timing 40000000 iterations of multiple, single...
> - multiple: 2 wallclock secs ( 2.20 usr + 0.00 sys = 2.20 CPU) @
> 18181818.18/s (n=40000000)
> - single: 2 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU) @
> 39603960.40/s (n=40000000)
> + multiple: 1 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @
> 35087719.30/s (n=40000000)
> + single: 1 wallclock secs ( 1.18 usr + 0.00 sys = 1.18 CPU) @
> 33898305.08/s (n=40000000)
>
> -real 0m25.807s
> -user 0m25.748s
> -sys 0m0.004s
> +real 0m22.227s
> +user 0m22.144s
> +sys 0m0.028s
>
> "my $a; my $b; return 1;" (multiple) goes from 18,181,818/s to
> 35,087,719/s, and overall run time
> of the tests goes from 25.8s to 22.s.
>
> What I find concerning is that "my ($a, $b); return 1;" appears to
> perform slightly worse; even though
> the runtime of the entire test goes down 1 second.
>
> I'm not sure if the optimisation is affecting Benchmark.pm's ability
> to judge or this is actually
> slowing down the latter case some how.
>
> If this is accepted in some form, I'll write the appropriate tests for
> B::Concise.
This makes sense to me, unless there's some controversy, I plan to apply it in a few days.
Tony
---
via perlbug: queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=121077
Thread Next