← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:42:38 2010
Reported on Wed Nov 17 22:04:44 2010

Filename/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm
StatementsExecuted 4123 statements in 68.1ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
10631121.0ms124msClass::MOP::Method::Wrapped::::__ANON__[:159]Class::MOP::Method::Wrapped::__ANON__[:159] (recurses: max depth 3, inclusive time 5.27ms)
66218.23ms21.7msClass::MOP::Method::Wrapped::::wrapClass::MOP::Method::Wrapped::wrap
61114.09ms8.24msClass::MOP::Method::Wrapped::::add_around_modifierClass::MOP::Method::Wrapped::add_around_modifier
66113.79ms3.79msClass::MOP::Method::Wrapped::::_newClass::MOP::Method::Wrapped::_new
134413.57ms3.57msClass::MOP::Method::Wrapped::::__ANON__[:69]Class::MOP::Method::Wrapped::__ANON__[:69]
61112.36ms2.36msClass::MOP::Method::Wrapped::::__ANON__[:161]Class::MOP::Method::Wrapped::__ANON__[:161]
511244µs438µsClass::MOP::Method::Wrapped::::add_before_modifierClass::MOP::Method::Wrapped::add_before_modifier
211179µs719msClass::MOP::Method::Wrapped::::__ANON__[:43]Class::MOP::Method::Wrapped::__ANON__[:43]
211111µs3.27msClass::MOP::Method::Wrapped::::__ANON__[:49]Class::MOP::Method::Wrapped::__ANON__[:49]
21171µs146µsClass::MOP::Method::Wrapped::::add_after_modifierClass::MOP::Method::Wrapped::add_after_modifier
11167µs86µsClass::MOP::Method::Wrapped::::BEGIN@4Class::MOP::Method::Wrapped::BEGIN@4
11139µs295µsClass::MOP::Method::Wrapped::::BEGIN@14Class::MOP::Method::Wrapped::BEGIN@14
11138µs107µsClass::MOP::Method::Wrapped::::BEGIN@5Class::MOP::Method::Wrapped::BEGIN@5
11137µs194µsClass::MOP::Method::Wrapped::::BEGIN@7Class::MOP::Method::Wrapped::BEGIN@7
11136µs163µsClass::MOP::Method::Wrapped::::BEGIN@8Class::MOP::Method::Wrapped::BEGIN@8
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:64]Class::MOP::Method::Wrapped::__ANON__[:64]
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:89]Class::MOP::Method::Wrapped::__ANON__[:89]
0000s0sClass::MOP::Method::Wrapped::::_make_compatible_withClass::MOP::Method::Wrapped::_make_compatible_with
0000s0sClass::MOP::Method::Wrapped::::after_modifiersClass::MOP::Method::Wrapped::after_modifiers
0000s0sClass::MOP::Method::Wrapped::::around_modifiersClass::MOP::Method::Wrapped::around_modifiers
0000s0sClass::MOP::Method::Wrapped::::before_modifiersClass::MOP::Method::Wrapped::before_modifiers
0000s0sClass::MOP::Method::Wrapped::::get_original_methodClass::MOP::Method::Wrapped::get_original_method
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1
2package Class::MOP::Method::Wrapped;
3
4397µs2104µs
# spent 86µs (67+19) within Class::MOP::Method::Wrapped::BEGIN@4 which was called: # once (67µs+19µs) by Class::MOP::Class::BEGIN@8 at line 4
use strict;
# spent 86µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@4 # spent 18µs making 1 call to strict::import
53102µs2176µs
# spent 107µs (38+69) within Class::MOP::Method::Wrapped::BEGIN@5 which was called: # once (38µs+69µs) by Class::MOP::Class::BEGIN@8 at line 5
use warnings;
# spent 107µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@5 # spent 69µs making 1 call to warnings::import
6
73101µs2351µs
# spent 194µs (37+157) within Class::MOP::Method::Wrapped::BEGIN@7 which was called: # once (37µs+157µs) by Class::MOP::Class::BEGIN@8 at line 7
use Carp 'confess';
# spent 194µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@7 # spent 157µs making 1 call to Exporter::import
83231µs2290µs
# spent 163µs (36+127) within Class::MOP::Method::Wrapped::BEGIN@8 which was called: # once (36µs+127µs) by Class::MOP::Class::BEGIN@8 at line 8
use Scalar::Util 'blessed';
# spent 163µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@8 # spent 127µs making 1 call to Exporter::import
9
1016µsour $VERSION = '1.11';
11162µs$VERSION = eval $VERSION;
# spent 11µs executing statements in string eval
1214µsour $AUTHORITY = 'cpan:STEVAN';
13
1433.37ms2551µs
# spent 295µs (39+256) within Class::MOP::Method::Wrapped::BEGIN@14 which was called: # once (39µs+256µs) by Class::MOP::Class::BEGIN@8 at line 14
use base 'Class::MOP::Method';
# spent 295µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@14 # spent 256µs making 1 call to base::import
15
16# NOTE:
17# this ugly beast is the result of trying
18# to micro optimize this as much as possible
19# while not completely loosing maintainability.
20# At this point it's "fast enough", after all
21# you can't get something for nothing :)
22
# spent 3.57ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:69] which was called 134 times, avg 27µs/call: # 66 times (1.82ms+0s) by Class::MOP::Method::Wrapped::wrap at line 87, avg 28µs/call # 61 times (1.49ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 171, avg 24µs/call # 5 times (194µs+0s) by Class::MOP::Method::Wrapped::add_before_modifier at line 128, avg 39µs/call # 2 times (75µs+0s) by Class::MOP::Method::Wrapped::add_after_modifier at line 140, avg 37µs/call
my $_build_wrapped_method = sub {
235364.12ms my $modifier_table = shift;
24 my ($before, $after, $around) = (
25 $modifier_table->{before},
26 $modifier_table->{after},
27 $modifier_table->{around},
28 );
29 if (@$before && @$after) {
30
# spent 719ms (179µs+719) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:43] which was called 2 times, avg 360ms/call: # 2 times (179µs+719ms) by Class::MOP::Class::__ANON__::SERIAL::2::install_accessors or Class::MOP::Class::__ANON__::SERIAL::5::install_accessors at line 89, avg 360ms/call
$modifier_table->{cache} = sub {
3114200µs2674ms for my $c (@$before) { $c->(@_) };
# spent 674ms making 2 calls to Class::MOP::Class:::before, avg 337ms/call
32 my @rval;
33244.8ms ((defined wantarray) ?
# spent 44.8ms making 2 calls to Moose::Meta::Attribute::install_accessors, avg 22.4ms/call
34 ((wantarray) ?
35 (@rval = $around->{cache}->(@_))
36 :
37 ($rval[0] = $around->{cache}->(@_)))
38 :
39 $around->{cache}->(@_));
40295µs for my $c (@$after) { $c->(@_) };
# spent 95µs making 2 calls to Class::MOP::Class:::after, avg 47µs/call
41 return unless defined wantarray;
42 return wantarray ? @rval : $rval[0];
43 }
44 }
45 elsif (@$before && !@$after) {
46
# spent 3.27ms (111µs+3.16) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:49] which was called 2 times, avg 1.63ms/call: # 2 times (111µs+3.16ms) by Class::MOP::Class::__ANON__::SERIAL::2::_process_options or Class::MOP::Class::__ANON__::SERIAL::5::_process_options at line 89, avg 1.63ms/call
$modifier_table->{cache} = sub {
476109µs21.80ms for my $c (@$before) { $c->(@_) };
# spent 1.80ms making 2 calls to Class::MOP::Class:::before, avg 902µs/call
4821.35ms return $around->{cache}->(@_);
# spent 1.35ms making 2 calls to Moose::Meta::Attribute::_process_options, avg 677µs/call
49 }
50 }
51 elsif (@$after && !@$before) {
52 $modifier_table->{cache} = sub {
53 my @rval;
54 ((defined wantarray) ?
55 ((wantarray) ?
56 (@rval = $around->{cache}->(@_))
57 :
58 ($rval[0] = $around->{cache}->(@_)))
59 :
60 $around->{cache}->(@_));
61 for my $c (@$after) { $c->(@_) };
62 return unless defined wantarray;
63 return wantarray ? @rval : $rval[0];
64 }
65 }
66 else {
67 $modifier_table->{cache} = $around->{cache};
68 }
69113µs};
70
71
# spent 21.7ms (8.23+13.5) within Class::MOP::Method::Wrapped::wrap which was called 66 times, avg 329µs/call: # 61 times (7.66ms+12.6ms) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:1108] at line 1094 of Class/MOP/Class.pm, avg 332µs/call # 5 times (565µs+892µs) by Class::MOP::Class::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Class.pm:1108] at line 1101 of Class/MOP/Class.pm, avg 291µs/call
sub wrap {
723309.15ms my ( $class, $code, %params ) = @_;
73
74132816µs (blessed($code) && $code->isa('Class::MOP::Method'))
# spent 454µs making 66 calls to UNIVERSAL::isa, avg 7µs/call # spent 361µs making 66 calls to Scalar::Util::blessed, avg 5µs/call
75 || confess "Can only wrap blessed CODE";
76
7766347µs my $modifier_table = {
# spent 347µs making 66 calls to Class::MOP::Method::body, avg 5µs/call
78 cache => undef,
79 orig => $code,
80 before => [],
81 after => [],
82 around => {
83 cache => $code->body,
84 methods => [],
85 },
86 };
87661.82ms $_build_wrapped_method->($modifier_table);
# spent 1.82ms making 66 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 28µs/call
88 return $class->SUPER::wrap(
89106720.4ms1067847ms sub { $modifier_table->{cache}->(@_) },
# spent 719ms making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:43], avg 360ms/call # spent 130ms making 1063 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:159], avg 122µs/call, recursion: max depth 3, sum of overlapping time 5.27ms # spent 3.27ms making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:49], avg 1.63ms/call
90 # get these from the original
91 # unless explicitly overriden
926610.5ms package_name => $params{package_name} || $code->package_name,
# spent 10.5ms making 66 calls to Class::MOP::Method::wrap, avg 159µs/call
93 name => $params{name} || $code->name,
94
95 modifier_table => $modifier_table,
96 );
97}
98
99
# spent 3.79ms within Class::MOP::Method::Wrapped::_new which was called 66 times, avg 57µs/call: # 66 times (3.79ms+0s) by Class::MOP::Method::wrap at line 44 of Class/MOP/Method.pm, avg 57µs/call
sub _new {
1002644.05ms my $class = shift;
101 return Class::MOP::Class->initialize($class)->new_object(@_)
102 if $class ne __PACKAGE__;
103
104 my $params = @_ == 1 ? $_[0] : {@_};
105
106 return bless {
107 # inherited from Class::MOP::Method
108 'body' => $params->{body},
109 'associated_metaclass' => $params->{associated_metaclass},
110 'package_name' => $params->{package_name},
111 'name' => $params->{name},
112 'original_method' => $params->{original_method},
113
114 # defined in this class
115 'modifier_table' => $params->{modifier_table}
116 } => $class;
117}
118
119sub get_original_method {
120 my $code = shift;
121 $code->{'modifier_table'}->{orig};
122}
123
124
# spent 438µs (244+194) within Class::MOP::Method::Wrapped::add_before_modifier which was called 5 times, avg 88µs/call: # 5 times (244µs+194µs) by Class::MOP::Class::add_before_method_modifier at line 1115 of Class/MOP/Class.pm, avg 88µs/call
sub add_before_modifier {
12520231µs my $code = shift;
126 my $modifier = shift;
127 unshift @{$code->{'modifier_table'}->{before}} => $modifier;
1285194µs $_build_wrapped_method->($code->{'modifier_table'});
# spent 194µs making 5 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 39µs/call
129}
130
131sub before_modifiers {
132 my $code = shift;
133 return @{$code->{'modifier_table'}->{before}};
134}
135
136
# spent 146µs (71+75) within Class::MOP::Method::Wrapped::add_after_modifier which was called 2 times, avg 73µs/call: # 2 times (71µs+75µs) by Class::MOP::Class::add_after_method_modifier at line 1125 of Class/MOP/Class.pm, avg 73µs/call
sub add_after_modifier {
137864µs my $code = shift;
138 my $modifier = shift;
139 push @{$code->{'modifier_table'}->{after}} => $modifier;
140275µs $_build_wrapped_method->($code->{'modifier_table'});
# spent 75µs making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 37µs/call
141}
142
143sub after_modifiers {
144 my $code = shift;
145 return @{$code->{'modifier_table'}->{after}};
146}
147
148{
149 # NOTE:
150 # this is another possible candidate for
151 # optimization as well. There is an overhead
152 # associated with the currying that, if
153 # eliminated might make around modifiers
154 # more manageable.
15514µs
# spent 2.36ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:161] which was called 61 times, avg 39µs/call: # 61 times (2.36ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 168, avg 39µs/call
my $compile_around_method = sub {{
1564882.69ms my $f1 = pop;
157 return $f1 unless @_;
158 my $f2 = pop;
159106319.2ms1063104ms
# spent 124ms (21.0+103) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/coding/src/Class-MOP/blib/lib//Class/MOP/Method/Wrapped.pm:159] which was called 1063 times, avg 117µs/call: # 1063 times (21.0ms+103ms) by Class::MOP::Class::Immutable::Class::MOP::Class::_method_map or Class::MOP::Class::Immutable::Class::MOP::Class::class_precedence_list or Class::MOP::Class::Immutable::Class::MOP::Class::get_all_attributes or Class::MOP::Class::Immutable::Class::MOP::Class::get_meta_instance or Class::MOP::Class::Immutable::Class::MOP::Class::is_immutable or Class::MOP::Class::Immutable::Class::MOP::Class::linearized_isa or Class::MOP::Class::Immutable::Class::MOP::Class::superclasses or Class::MOP::Class::Immutable::Moose::Meta::Class::_method_map or Class::MOP::Class::Immutable::Moose::Meta::Class::class_precedence_list or Class::MOP::Class::Immutable::Moose::Meta::Class::is_immutable or Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa or Class::MOP::Class::Immutable::Moose::Meta::Class::superclasses or Class::MOP::Class::__ANON__::SERIAL::2::_canonicalize_handles or Class::MOP::Class::__ANON__::SERIAL::2::_make_delegation_method or Class::MOP::Class::__ANON__::SERIAL::3::new or Class::MOP::Class::__ANON__::SERIAL::4::new or Class::MOP::Class::__ANON__::SERIAL::5::_canonicalize_handles or Class::MOP::Class::__ANON__::SERIAL::5::_make_delegation_method or Class::MOP::Class::__ANON__::SERIAL::6::_eval_environment or Class::MOP::Class::__ANON__::SERIAL::6::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::6::new or Class::MOP::Class::__ANON__::SERIAL::7::new or Class::MOP::Class::__ANON__::SERIAL::8::_eval_environment or Class::MOP::Class::__ANON__::SERIAL::8::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::8::new at line 89, avg 117µs/call
push @_, sub { $f2->( $f1, @_ ) };
# spent 109ms making 1063 calls to Class::MOP::Class:::around, avg 102µs/call, recursion: max depth 3, sum of overlapping time 5.06ms
160 redo;
16118µs }};
162
163
# spent 8.24ms (4.09+4.15) within Class::MOP::Method::Wrapped::add_around_modifier which was called 61 times, avg 135µs/call: # 61 times (4.09ms+4.15ms) by Class::MOP::Class::add_around_method_modifier at line 1135 of Class/MOP/Class.pm, avg 135µs/call
sub add_around_modifier {
1643053.95ms my $code = shift;
165 my $modifier = shift;
166 unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier;
167 $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->(
1681222.67ms @{$code->{'modifier_table'}->{around}->{methods}},
# spent 2.36ms making 61 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:161], avg 39µs/call # spent 304µs making 61 calls to Class::MOP::Method::body, avg 5µs/call
169 $code->{'modifier_table'}->{orig}->body
170 );
171611.49ms $_build_wrapped_method->($code->{'modifier_table'});
# spent 1.49ms making 61 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 24µs/call
172 }
173}
174
175sub around_modifiers {
176 my $code = shift;
177 return @{$code->{'modifier_table'}->{around}->{methods}};
178}
179
180sub _make_compatible_with {
181 my $self = shift;
182 my ($other) = @_;
183
184 # XXX: this is pretty gross. the issue here is that CMOP::Method::Wrapped
185 # objects are subclasses of CMOP::Method, but when we get to moose, they'll
186 # need to be compatible with Moose::Meta::Method, which isn't possible. the
187 # right solution here is to make ::Wrapped into a role that gets applied to
188 # whatever the method_metaclass happens to be and get rid of
189 # wrapped_method_metaclass entirely, but that's not going to happen until
190 # we ditch cmop and get roles into the bootstrapping, so. i'm not
191 # maintaining the previous behavior of turning them into instances of the
192 # new method_metaclass because that's equally broken, and at least this way
193 # any issues will at least be detectable and potentially fixable. -doy
194 return $self unless $other->_is_compatible_with($self->_real_ref_name);
195
196 return $self->SUPER::_make_compatible_with(@_);
197}
198
199116µs1;
200
201__END__