← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:39:01 2010
Reported on Wed Nov 17 22:05:18 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm
StatementsExecuted 4399 statements in 72.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
10661121.8ms136msClass::MOP::Method::Wrapped::::__ANON__[:159]Class::MOP::Method::Wrapped::__ANON__[:159] (recurses: max depth 3, inclusive time 6.34ms)
75219.57ms25.1msClass::MOP::Method::Wrapped::::wrapClass::MOP::Method::Wrapped::wrap
70114.70ms9.64msClass::MOP::Method::Wrapped::::add_around_modifierClass::MOP::Method::Wrapped::add_around_modifier
75114.12ms4.12msClass::MOP::Method::Wrapped::::_newClass::MOP::Method::Wrapped::_new
152413.98ms3.98msClass::MOP::Method::Wrapped::::__ANON__[:69]Class::MOP::Method::Wrapped::__ANON__[:69]
70112.88ms2.88msClass::MOP::Method::Wrapped::::__ANON__[:161]Class::MOP::Method::Wrapped::__ANON__[:161]
211216µs364msClass::MOP::Method::Wrapped::::__ANON__[:43]Class::MOP::Method::Wrapped::__ANON__[:43]
511174µs352µsClass::MOP::Method::Wrapped::::add_before_modifierClass::MOP::Method::Wrapped::add_before_modifier
211112µs3.26msClass::MOP::Method::Wrapped::::__ANON__[:49]Class::MOP::Method::Wrapped::__ANON__[:49]
11173µs92µsClass::MOP::Method::Wrapped::::BEGIN@4Class::MOP::Method::Wrapped::BEGIN@4
21171µs143µsClass::MOP::Method::Wrapped::::add_after_modifierClass::MOP::Method::Wrapped::add_after_modifier
11139µs198µsClass::MOP::Method::Wrapped::::BEGIN@7Class::MOP::Method::Wrapped::BEGIN@7
11139µs282µsClass::MOP::Method::Wrapped::::BEGIN@14Class::MOP::Method::Wrapped::BEGIN@14
11138µs108µsClass::MOP::Method::Wrapped::::BEGIN@5Class::MOP::Method::Wrapped::BEGIN@5
11135µs162µ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
4399µs2111µs
# spent 92µs (73+19) within Class::MOP::Method::Wrapped::BEGIN@4 which was called: # once (73µs+19µs) by Class::MOP::Class::BEGIN@8 at line 4
use strict;
# spent 92µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@4 # spent 19µs making 1 call to strict::import
53110µs2177µs
# spent 108µs (38+70) within Class::MOP::Method::Wrapped::BEGIN@5 which was called: # once (38µs+70µs) by Class::MOP::Class::BEGIN@8 at line 5
use warnings;
# spent 108µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@5 # spent 70µs making 1 call to warnings::import
6
73100µs2356µs
# spent 198µs (39+158) within Class::MOP::Method::Wrapped::BEGIN@7 which was called: # once (39µs+158µs) by Class::MOP::Class::BEGIN@8 at line 7
use Carp 'confess';
# spent 198µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@7 # spent 158µs making 1 call to Exporter::import
83210µs2290µs
# spent 162µs (35+128) within Class::MOP::Method::Wrapped::BEGIN@8 which was called: # once (35µs+128µs) by Class::MOP::Class::BEGIN@8 at line 8
use Scalar::Util 'blessed';
# spent 162µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@8 # spent 128µs making 1 call to Exporter::import
9
1016µsour $VERSION = '1.11';
11164µs$VERSION = eval $VERSION;
# spent 12µs executing statements in string eval
1214µsour $AUTHORITY = 'cpan:STEVAN';
13
1433.33ms2525µs
# spent 282µs (39+243) within Class::MOP::Method::Wrapped::BEGIN@14 which was called: # once (39µs+243µs) by Class::MOP::Class::BEGIN@8 at line 14
use base 'Class::MOP::Method';
# spent 282µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@14 # spent 243µ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.98ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:69] which was called 152 times, avg 26µs/call: # 75 times (2.03ms+0s) by Class::MOP::Method::Wrapped::wrap at line 87, avg 27µs/call # 70 times (1.70ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 171, avg 24µs/call # 5 times (177µs+0s) by Class::MOP::Method::Wrapped::add_before_modifier at line 128, avg 35µs/call # 2 times (72µs+0s) by Class::MOP::Method::Wrapped::add_after_modifier at line 140, avg 36µs/call
my $_build_wrapped_method = sub {
234563.95ms my $modifier_table = shift;
24 my ($before, $after, $around) = (
25 $modifier_table->{before},
26 $modifier_table->{after},
27 $modifier_table->{around},
28 );
29152601µs if (@$before && @$after) {
30
# spent 364ms (216µs+364) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:43] which was called 2 times, avg 182ms/call: # 2 times (216µs+364ms) by Class::MOP::Class::__ANON__::SERIAL::2::install_accessors or Class::MOP::Class::__ANON__::SERIAL::5::install_accessors at line 89, avg 182ms/call
$modifier_table->{cache} = sub {
3112137µs2322ms for my $c (@$before) { $c->(@_) };
# spent 322ms making 2 calls to Class::MOP::Class:::before, avg 161ms/call
32 my @rval;
33241.5ms ((defined wantarray) ?
# spent 41.5ms making 2 calls to Moose::Meta::Attribute::install_accessors, avg 20.8ms/call
34 ((wantarray) ?
35 (@rval = $around->{cache}->(@_))
36 :
37 ($rval[0] = $around->{cache}->(@_)))
38 :
39 $around->{cache}->(@_));
40233µs292µs for my $c (@$after) { $c->(@_) };
# spent 92µs making 2 calls to Class::MOP::Class:::after, avg 46µs/call
41 return unless defined wantarray;
42 return wantarray ? @rval : $rval[0];
43 }
44 }
45 elsif (@$before && !@$after) {
46
# spent 3.26ms (112µs+3.15) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:49] which was called 2 times, avg 1.63ms/call: # 2 times (112µs+3.15ms) 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 {
476111µs21.86ms for my $c (@$before) { $c->(@_) };
# spent 1.86ms making 2 calls to Class::MOP::Class:::before, avg 931µs/call
4821.29ms return $around->{cache}->(@_);
# spent 1.29ms making 2 calls to Moose::Meta::Attribute::_process_options, avg 644µ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 25.1ms (9.57+15.5) within Class::MOP::Method::Wrapped::wrap which was called 75 times, avg 334µs/call: # 66 times (8.51ms+13.8ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:967] at line 953 of Class/MOP/Class.pm, avg 338µs/call # 9 times (1.06ms+1.73ms) by Class::MOP::Class::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Class.pm:967] at line 960 of Class/MOP/Class.pm, avg 310µs/call
sub wrap {
7237510.8ms my ( $class, $code, %params ) = @_;
73
741501.04ms (blessed($code) && $code->isa('Class::MOP::Method'))
# spent 532µs making 75 calls to UNIVERSAL::isa, avg 7µs/call # spent 506µs making 75 calls to Scalar::Util::blessed, avg 7µs/call
75 || confess "Can only wrap blessed CODE";
76
7775350µs my $modifier_table = {
# spent 350µs making 75 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 };
87752.03ms $_build_wrapped_method->($modifier_table);
# spent 2.03ms making 75 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 27µs/call
88 return $class->SUPER::wrap(
89107020.8ms1070504ms sub { $modifier_table->{cache}->(@_) },
# spent 364ms making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:43], avg 182ms/call # spent 143ms making 1066 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:159], avg 134µs/call, recursion: max depth 3, sum of overlapping time 6.34ms # spent 3.26ms 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
927512.1ms package_name => $params{package_name} || $code->package_name,
# spent 12.1ms making 75 calls to Class::MOP::Method::wrap, avg 161µs/call
93 name => $params{name} || $code->name,
94
95 modifier_table => $modifier_table,
96 );
97}
98
99
# spent 4.12ms within Class::MOP::Method::Wrapped::_new which was called 75 times, avg 55µs/call: # 75 times (4.12ms+0s) by Class::MOP::Method::wrap at line 44 of Class/MOP/Method.pm, avg 55µs/call
sub _new {
1003004.49ms 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 352µs (174+177) within Class::MOP::Method::Wrapped::add_before_modifier which was called 5 times, avg 70µs/call: # 5 times (174µs+177µs) by Class::MOP::Class::add_before_method_modifier at line 974 of Class/MOP/Class.pm, avg 70µs/call
sub add_before_modifier {
12520159µs my $code = shift;
126 my $modifier = shift;
127 unshift @{$code->{'modifier_table'}->{before}} => $modifier;
1285177µs $_build_wrapped_method->($code->{'modifier_table'});
# spent 177µs making 5 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 35µs/call
129}
130
131sub before_modifiers {
132 my $code = shift;
133 return @{$code->{'modifier_table'}->{before}};
134}
135
136
# spent 143µs (71+72) within Class::MOP::Method::Wrapped::add_after_modifier which was called 2 times, avg 72µs/call: # 2 times (71µs+72µs) by Class::MOP::Class::add_after_method_modifier at line 984 of Class/MOP/Class.pm, avg 72µs/call
sub add_after_modifier {
137866µs my $code = shift;
138 my $modifier = shift;
139 push @{$code->{'modifier_table'}->{after}} => $modifier;
140272µs $_build_wrapped_method->($code->{'modifier_table'});
# spent 72µs making 2 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:69], avg 36µ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.
1554913.02ms
# spent 2.88ms within Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:161] which was called 70 times, avg 41µs/call: # 70 times (2.88ms+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 168, avg 41µs/call
my $compile_around_method = sub {{
15670175µs my $f1 = pop;
157 return $f1 unless @_;
158 my $f2 = pop;
159106619.9ms1066115ms
# spent 136ms (21.8+115) within Class::MOP::Method::Wrapped::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm:159] which was called 1066 times, avg 128µs/call: # 1066 times (21.8ms+115ms) 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::3::new or Class::MOP::Class::__ANON__::SERIAL::4::_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_coerce_new_values or Class::MOP::Class::__ANON__::SERIAL::6::_inline_get_old_value_for_trigger or Class::MOP::Class::__ANON__::SERIAL::6::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::6::_new or Class::MOP::Class::__ANON__::SERIAL::6::_value_needs_copy or Class::MOP::Class::__ANON__::SERIAL::6::new or Class::MOP::Class::__ANON__::SERIAL::7::_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_coerce_new_values or Class::MOP::Class::__ANON__::SERIAL::8::_inline_get_old_value_for_trigger or Class::MOP::Class::__ANON__::SERIAL::8::_inline_tc_code or Class::MOP::Class::__ANON__::SERIAL::8::_new or Class::MOP::Class::__ANON__::SERIAL::8::_value_needs_copy or Class::MOP::Class::__ANON__::SERIAL::8::new at line 89, avg 128µs/call
push @_, sub { $f2->( $f1, @_ ) };
# spent 121ms making 1066 calls to Class::MOP::Class:::around, avg 113µs/call, recursion: max depth 3, sum of overlapping time 6.09ms
160 redo;
16119µs }};
162
163
# spent 9.64ms (4.70+4.95) within Class::MOP::Method::Wrapped::add_around_modifier which was called 70 times, avg 138µs/call: # 70 times (4.70ms+4.95ms) by Class::MOP::Class::add_around_method_modifier at line 994 of Class/MOP/Class.pm, avg 138µs/call
sub add_around_modifier {
1643504.59ms my $code = shift;
165 my $modifier = shift;
166 unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier;
167 $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->(
1681403.24ms @{$code->{'modifier_table'}->{around}->{methods}},
# spent 2.88ms making 70 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:161], avg 41µs/call # spent 366µs making 70 calls to Class::MOP::Method::body, avg 5µs/call
169 $code->{'modifier_table'}->{orig}->body
170 );
171701.70ms $_build_wrapped_method->($code->{'modifier_table'});
# spent 1.70ms making 70 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__