Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When doing a reduction, we are going to need the whole list anyway. I…
…nstead of chewing it element by element, instead take it in bigger chunks. This reduces the fixed-size overhead per reificication which, in the case of reifying a range, is massively greater than the time to produce a single value. With this and the previous patch [+] 1..1000 runs in 8% of the time it did before; TimToady++ for pointing out this epic performance fail.
  • Loading branch information
jnthn committed Feb 12, 2012
1 parent 2c672ae commit 6810cc6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core/metaops.pm
Expand Up @@ -64,8 +64,11 @@ sub METAOP_REDUCE(\$op, :$triangle) {
return $op() unless @values.gimme(1);
my $result := @values.shift;
return $op($result) unless @values.gimme(1);
$result := $op($result, @values.shift)
while @values.gimme(1);
while @values.gimme(1000) {
my int $i = 0;
$result := $op($result, @values.shift)
while ($i = $i + 1) < 1000 && @values.gimme(1);
}
$result;
})
}
Expand All @@ -87,8 +90,11 @@ sub METAOP_REDUCE_RIGHT(\$op, :$triangle) {
return $op() unless $list.gimme(1);
my $result := $list.shift;
return $op($result) unless $list.gimme(1);
$result := $op($list.shift, $result)
while $list.gimme(1);
while $list.gimme(1000) {
my int $i = 0;
$result := $op($list.shift, $result)
while ($i = $i + 1) < 1000 && $list.gimme(1);
}
$result;
}
}
Expand Down

0 comments on commit 6810cc6

Please sign in to comment.