On Wed, Nov 25, 2009 at 11:17 AM, Eric Brine <ikegami@adaelis.com> wrote:
> On Wed, Nov 25, 2009 at 3:26 AM, Abigail <abigail@abigail.be> wrote:
>
>> It does however have the potential to break code.
>>
>
> Yes. Specifically, it'll break code (noisily) that modifies what Perl
> treats as constants. I even had to fix such a bug in t/op/mydef.t. This is
> what the submitter and the responders requested. If you'd rather I do it
> differently, I'm up to giving it a go.
>
Since the bug is due to an optimisation, I figured it would be worthwhile to
benchmark the usefulness of the optimisation.
There's almost no difference for small lists. For long lists, the
optimisation results in a substantial difference in performance.
$ git diff
diff --git a/op.c b/op.c
index d4f6fb3..32fa2b4 100644
--- a/op.c
+++ b/op.c
@@ -2590,6 +2590,8 @@ S_gen_constant_list(pTHX_ register OP *o)
register OP *curop;
const I32 oldtmps_floor = PL_tmps_floor;
+ return o;
+
list(o);
if (PL_parser && PL_parser->error_count)
return o; /* Don't attempt to run with errors */
$ cat a.pl
use Time::HiRes qw( time );
my $N = $ARGV[0] || 2000;
my $s_time = time;
my @a = map { my $p=$_; map { "$p:$_" } 1..$N } 1..$N;
my $e_time = time;
print($e_time - $s_time, "\n");
Blead (at 789c461534f3eb0346447f8127786b7da3017f6c):
$ for q in 1 2 3 4 5 6 ; do perl -Ilib a.pl 20 ; done
0.000880002975463867
0.000934123992919922
0.000874042510986328
0.000941991806030273
0.000870943069458008
0.000852108001708984
avg: 0.000892202059427897
$ for q in 1 2 3 4 5 6 ; do perl -Ilib a.pl 2000 ; done
6.18947696685791
6.17325901985168
6.38008713722229
6.51624393463135
6.2569899559021
6.23375201225281
avg: 6.29163483778636
Blead with optimisation removed:
$ for q in 1 2 3 4 5 6 ; do perl -Ilib a.pl 20 ; done
0.000860929489135742
0.000841140747070312
0.000859975814819336
0.000878810882568359
0.000877141952514648
0.000889062881469727
avg: 0.000867843627929687
$ for q in 1 2 3 4 5 6 ; do perl -Ilib a.pl 2000 ; done
9.09057521820068
8.82025122642517
9.41165494918823
8.80950093269348
9.01842403411865
8.80255198478699
avg: 8.99215972423553
- ELB
Thread Previous