develooper Front page | perl.perl5.porters | Postings from October 2016

Re: [perl #127999] Slowdown in split + list assign

Thread Previous
From:
demerphq
Date:
October 21, 2016 16:20
Subject:
Re: [perl #127999] Slowdown in split + list assign
Message ID:
CANgJU+XvnKgJw4U_ZN-o-JE1k1RFyuxj3YKZbU2WuBvBqUM=0w@mail.gmail.com
You are my hero.☺️

Thanks dave

On 21 Oct 2016 5:24 p.m., "Dave Mitchell" <davem@iabyn.com> wrote:

> On Fri, Sep 16, 2016 at 11:14:38PM +0100, Dave Mitchell wrote:
> > I intend to revisit it soon.
>
> I've now revisited it, with the branch smoke-me/davem/aassign currently
> being smoked. It turned out that the slowdown in split between 5.22.0 and
> 5.24.0 was (mostly) not in fact due to the OPpASSIGN_COMMON_AGG flag being
> incorrectly set on the AASSIGN op.
>
> In fact, it's due to a bug fix in 5.24.0. Formerly, the AASSIGN op would
> steal the string buffer of RHS temporaries when copying the values. This
> failed when the same temporary appeared twice on the RHS, as in e.g.
>
>     @a = (split())[0,0]
>
> where split (and other such functions return temporaries). 5.24.0 started
> using the SV_NOSTEAL flag for the copy, which give the correct behaviour,
> but slowed down many list assignments where the RHS contained strings.
>
> In the branch above I've completely reworked the slurpy part of
> pp_aaasign(), with the result that many lists assigns are now much, much
> faster (not just than 5.24.0, but much faster than 5.22.0 too).
>
> Benchmarking the two examples in this ticket, using 'perf stat -r 10' to
> count CPU cycles:
>
>     for my $i (1..300_000) {
>         my @a = ((split //, "1"x100), "-");
>     }
>
>         5.22.0    11,075,364,115 CPU cycles
>         5.24.0    15,821,609,317
>         5.25.5    15,648,800,025
>         my branch  7,641,656,944
>
>     @array_of_strings  = qw(stnstntsn stnstnstnstns stnstnstnstn
> snstnstnstn
>         ccvdvdvdvzddvd);
>     for my $i (1..300_000) {
>         @array = map { split(//, $_), 'separator' } @array_of_strings;
>     }
>
>         5.22.0    12,935,451,207
>         5.24.0    11,706,821,273
>         5.25.5    11,233,362,837
>         my branch  6,091,583,255
>
> And here are some further performance comments taken from the commit
> message:
>
>
>     Here are the average expr::aassign:: benchmarks for selected perls
>     (raw numbers - lower is better)
>
>               5.6.1    5.22.0    5.24.0    5.25.5      this
>              ------    ------    ------    ------    ------
>         Ir   1355.9    1497.8    1387.0    1382.0    1146.6
>         Dr    417.2     454.2     410.1     411.1     335.2
>         Dw    260.6     270.8     249.0     246.8     194.5
>       COND    193.5     223.2     212.0     207.7     174.4
>        IND     25.3      17.6      10.8      10.8      10.0
>
>     COND_m      4.1       3.1       3.1       3.7       2.8
>      IND_m      8.9       6.1       5.5       5.5       5.5
>
>     And this code:
>
>         my @a;
>         for my $i (1..10_000_000) {
>             @a = (1,2,3);
>             #@a = ();
>         }
>
>     with the empty assign is 33% faster than blead, and without is 12%
> faster
>     than blead.
>
>
>
> --
> "You're so sadly neglected, and often ignored.
> A poor second to Belgium, When going abroad."
>     -- Monty Python, "Finland"
>

Thread Previous


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