Skip Menu |

This queue is for tickets about the parent CPAN distribution.

Report information
The Basics
Id: 62341
Status: resolved
Priority: 0/
Queue: parent

People
Owner: Nobody in particular
Requestors: ribasushi [...] leporine.io
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Immense speed regression when used over same class
I know this is an esoteric case, but nevertheless it can happen in the wild. I also am not including any patches as I can not see how this is even possible (parent.pm is rather simple...) use strictures 1; use Benchmark qw/cmpthese/; require parent; require base; { package Bench::Base; sub foo { 1 }; } my $c; my $sub_iter = 100; cmpthese (-1 => { use_base => sub { $c++; for (1..$sub_iter) { my $class = "Bench::Bas::Sub_${c}::SubSub${_}"; eval "package $class; use base 'Bench::Base'"; die unless $class->foo; } }, use_base_same_class => sub { $c++; for (1..$sub_iter) { my $class = "Bench::Bas::Sub_${c}"; eval "package $class; use base 'Bench::Base'"; die unless $class->foo; } }, use_parent => sub { $c++; for (1..$sub_iter) { my $class = "Bench::Par::Sub_${c}::SubSub${_}"; eval "package $class; use parent -norequire => 'Bench::Base'"; die unless $class->foo; } }, use_parent_same_class => sub { $c++; for (1..$sub_iter) { my $class = "Bench::Par::Sub_${c}"; eval "package $class; use parent -norequire => 'Bench::Base'"; die unless $class->foo; } }, }); __END__ perl <= 5.8.9 (tested on 5.6.2, 5.8.1, 5.8.9 nearly identical numbers) Rate use_parent_same_class use_base use_parent use_base_same_class use_parent_same_class 121/s -- -28% -42% -54% use_base 168/s 39% -- -19% -36% use_parent 208/s 72% 24% -- -21% use_base_same_class 262/s 116% 56% 26% -- perl > 5.8.9 (tested on 5.10.1, 5.12.1 nearly identical numbers) Rate use_parent_same_class use_base use_parent use_base_same_class use_parent_same_class 9.43/s -- -93% -95% -96% use_base 141/s 1392% -- -18% -48% use_parent 172/s 1726% 22% -- -36% use_base_same_class 269/s 2754% 91% 56% -- perl 5.13.4 Rate use_parent_same_class use_base use_parent use_base_same_class use_parent_same_class 76.4/s -- -37% -51% -66% use_base 121/s 58% -- -22% -46% use_parent 155/s 102% 28% -- -30% use_base_same_class 222/s 191% 84% 44% --
Subject: Re: [rt.cpan.org #62341] Immense speed regression when used over same class
Date: Thu, 21 Oct 2010 17:58:00 +0200
To: bug-parent [...] rt.cpan.org
From: Max Maischein <corion [...] corion.net>
Hello Peter, Show quoted text
> I know this is an esoteric case, but nevertheless it can happen in the > wild. I also am not including any patches as I can not see how this is > even possible (parent.pm is rather simple...)
My guess is the push @{"$inheritor\::ISA"}, @isa_classes; push @{"$inheritor\::ISA"}, @bases; in base.pm versus { no strict 'refs'; # This is more efficient than push for the new MRO # at least until the new MRO is fixed @{"$inheritor\::ISA"} = (@{"$inheritor\::ISA"} , @_); }; in parent.pm , as they both blow Perls method cache. Maybe use_parent_same_class makes @ISA grow, which makes Perl slow, as it's recalculating the methods for the class over and over again? This slowness can likely be reproduced without involving base.pm and parent.pm by directly manipulating @ISA. -max
Subject: Re: [rt.cpan.org #62341] Immense speed regression when used over same class
Date: Sun, 31 Oct 2010 21:29:37 +0100
To: bug-parent [...] rt.cpan.org
From: Max Maischein <corion [...] corion.net>
Hello all, Show quoted text
> This slowness can likely be reproduced without involving base.pm and > parent.pm by directly manipulating @ISA.
Indeed - attached is the benchmark that divides up the (at least) three dimensions that influence how many iterations get done: a) array assignment or push b) new (empty) array / existing array c) @ISA or @FOO It seems intuitive that pushing onto an array is faster than recomputing the array contents. This will be changed in parent.pm 0.224, as parent 0.223 still uses @ISA = (@ISA,'new::class'), which at one time was claimed to be faster. When a new package is created, there is some overhead, which explains the difference between pushing onto an existing package variable or a new one, but an existing @ISA is slower to search than an empty @ISA, which could explain why the rate of pushing onto an existing/empty @ISA is 4/7 (at least on this bleadperl 2748c776108ea3c2dab18eeb6a710e819486df17, on this machine). Using a plain package variable @FOO to calibrate seems to amortize the cost of setting up a new package over the 100 runs. -max

Message body is not shown because sender requested not to inline it.

This was fixed somewhen after 5.12