| Filename | /home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Wrapped.pm |
| Statements | Executed 4399 statements in 72.8ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1066 | 1 | 1 | 21.8ms | 136ms | Class::MOP::Method::Wrapped::__ANON__[:159] (recurses: max depth 3, inclusive time 6.34ms) |
| 75 | 2 | 1 | 9.57ms | 25.1ms | Class::MOP::Method::Wrapped::wrap |
| 70 | 1 | 1 | 4.70ms | 9.64ms | Class::MOP::Method::Wrapped::add_around_modifier |
| 75 | 1 | 1 | 4.12ms | 4.12ms | Class::MOP::Method::Wrapped::_new |
| 152 | 4 | 1 | 3.98ms | 3.98ms | Class::MOP::Method::Wrapped::__ANON__[:69] |
| 70 | 1 | 1 | 2.88ms | 2.88ms | Class::MOP::Method::Wrapped::__ANON__[:161] |
| 2 | 1 | 1 | 216µs | 364ms | Class::MOP::Method::Wrapped::__ANON__[:43] |
| 5 | 1 | 1 | 174µs | 352µs | Class::MOP::Method::Wrapped::add_before_modifier |
| 2 | 1 | 1 | 112µs | 3.26ms | Class::MOP::Method::Wrapped::__ANON__[:49] |
| 1 | 1 | 1 | 73µs | 92µs | Class::MOP::Method::Wrapped::BEGIN@4 |
| 2 | 1 | 1 | 71µs | 143µs | Class::MOP::Method::Wrapped::add_after_modifier |
| 1 | 1 | 1 | 39µs | 198µs | Class::MOP::Method::Wrapped::BEGIN@7 |
| 1 | 1 | 1 | 39µs | 282µs | Class::MOP::Method::Wrapped::BEGIN@14 |
| 1 | 1 | 1 | 38µs | 108µs | Class::MOP::Method::Wrapped::BEGIN@5 |
| 1 | 1 | 1 | 35µs | 162µs | Class::MOP::Method::Wrapped::BEGIN@8 |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:64] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::__ANON__[:89] |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::_make_compatible_with |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::after_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::around_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::before_modifiers |
| 0 | 0 | 0 | 0s | 0s | Class::MOP::Method::Wrapped::get_original_method |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package Class::MOP::Method::Wrapped; | ||||
| 3 | |||||
| 4 | 3 | 99µs | 2 | 111µ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 # spent 92µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@4
# spent 19µs making 1 call to strict::import |
| 5 | 3 | 110µs | 2 | 177µ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 # spent 108µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@5
# spent 70µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 100µs | 2 | 356µ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 # spent 198µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@7
# spent 158µs making 1 call to Exporter::import |
| 8 | 3 | 210µs | 2 | 290µ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 # spent 162µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@8
# spent 128µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 6µs | our $VERSION = '1.11'; | ||
| 11 | 1 | 64µs | $VERSION = eval $VERSION; # spent 12µs executing statements in string eval | ||
| 12 | 1 | 4µs | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 3.33ms | 2 | 525µ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 # 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 | ||||
| 23 | 456 | 3.95ms | my $modifier_table = shift; | ||
| 24 | my ($before, $after, $around) = ( | ||||
| 25 | $modifier_table->{before}, | ||||
| 26 | $modifier_table->{after}, | ||||
| 27 | $modifier_table->{around}, | ||||
| 28 | ); | ||||
| 29 | 152 | 601µ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 | ||||
| 31 | 12 | 137µs | 2 | 322ms | for my $c (@$before) { $c->(@_) }; # spent 322ms making 2 calls to Class::MOP::Class:::before, avg 161ms/call |
| 32 | my @rval; | ||||
| 33 | 2 | 41.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}->(@_)); | ||||
| 40 | 2 | 33µs | 2 | 92µ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 | ||||
| 47 | 6 | 111µs | 2 | 1.86ms | for my $c (@$before) { $c->(@_) }; # spent 1.86ms making 2 calls to Class::MOP::Class:::before, avg 931µs/call |
| 48 | 2 | 1.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 | } | ||||
| 69 | 1 | 13µ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 | ||||
| 72 | 375 | 10.8ms | my ( $class, $code, %params ) = @_; | ||
| 73 | |||||
| 74 | 150 | 1.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 | |||||
| 77 | 75 | 350µ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 | }; | ||||
| 87 | 75 | 2.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( | ||||
| 89 | 1070 | 20.8ms | 1070 | 504ms | 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 | ||||
| 92 | 75 | 12.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 | ||||
| 100 | 300 | 4.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 | |||||
| 119 | sub 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 | ||||
| 125 | 20 | 159µs | my $code = shift; | ||
| 126 | my $modifier = shift; | ||||
| 127 | unshift @{$code->{'modifier_table'}->{before}} => $modifier; | ||||
| 128 | 5 | 177µ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 | |||||
| 131 | sub 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 | ||||
| 137 | 8 | 66µs | my $code = shift; | ||
| 138 | my $modifier = shift; | ||||
| 139 | push @{$code->{'modifier_table'}->{after}} => $modifier; | ||||
| 140 | 2 | 72µ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 | |||||
| 143 | sub 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. | ||||
| 155 | 491 | 3.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 | ||
| 156 | 70 | 175µs | my $f1 = pop; | ||
| 157 | return $f1 unless @_; | ||||
| 158 | my $f2 = pop; | ||||
| 159 | 1066 | 19.9ms | 1066 | 115ms | # 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 # 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; | ||||
| 161 | 1 | 9µ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 | ||||
| 164 | 350 | 4.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->( | ||||
| 168 | 140 | 3.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 | ); | ||||
| 171 | 70 | 1.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 | |||||
| 175 | sub around_modifiers { | ||||
| 176 | my $code = shift; | ||||
| 177 | return @{$code->{'modifier_table'}->{around}->{methods}}; | ||||
| 178 | } | ||||
| 179 | |||||
| 180 | sub _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 | |||||
| 199 | 1 | 16µs | 1; | ||
| 200 | |||||
| 201 | __END__ |