http://qs1969.pair.com?node_id=348329


in reply to Re: Re: May Thy Closures Be Blessed
in thread May Thy Closures Be Blessed

This is probably due to inefficient stringification of the object reference. Maybe the stringified value should be put into the PV portion and POK should be set on while doing Perl_sv_2pv_flags ?

I think this evaluation is spot on. If you change the inside-out implementation to something that avoids stringification:

package Class_Inside_Out; use Scalar::Util qw(refaddr); my %name; my %colour; my %age; sub new { my $key = bless \(my $dummy) => shift; $$key = refaddr ( $key ); my %args = @_; $name {$$key} = $args {name} || "abigail"; $colour {$$key} = $args {colour} || "pink"; $age {$$key} = $args {age} || 100; $key; } sub name { my $key = shift; $name {$$key} = shift if @_; $name {$$key}; } sub colour { my $key = shift; $colour {$$key} = shift if @_; $colour {$$key}; } sub age { my $key = shift; $age {$$key} = shift if @_; $age {$$key}; } sub format { my $key = shift; join " " => $name {$$key}, $colour {$$key}, $age {$$key}; }

You get something much more reasonable:

Rate closure inside_out traditional closure 177/s -- -43% -45% inside_out 313/s 76% -- -3% traditional 321/s 81% 3% --