← Index
NYTProf Performance Profile   « block view • line view • sub view »
For mentat.storage.mongo.pl
  Run on Tue Jun 24 09:58:41 2014
Reported on Tue Jun 24 09:59:32 2014

Filename/usr/local/lib/perl/5.14.2/Class/MOP/Method/Wrapped.pm
StatementsExecuted 3451 statements in 8.02ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
981112.49ms19.3msClass::MOP::Method::Wrapped::::__ANON__[:162]Class::MOP::Method::Wrapped::__ANON__[:162]
4611958µs2.39msClass::MOP::Method::Wrapped::::wrapClass::MOP::Method::Wrapped::wrap
4611507µs507µsClass::MOP::Method::Wrapped::::_newClass::MOP::Method::Wrapped::_new
4611389µs776µsClass::MOP::Method::Wrapped::::add_around_modifierClass::MOP::Method::Wrapped::add_around_modifier
9221276µs276µsClass::MOP::Method::Wrapped::::__ANON__[:71]Class::MOP::Method::Wrapped::__ANON__[:71]
4611255µs255µsClass::MOP::Method::Wrapped::::__ANON__[:164]Class::MOP::Method::Wrapped::__ANON__[:164]
11110µs15µsClass::MOP::Method::Wrapped::::BEGIN@11Class::MOP::Method::Wrapped::BEGIN@11
1118µs8µsClass::MOP::Method::Wrapped::::BEGIN@3Class::MOP::Method::Wrapped::BEGIN@3
1117µs11µsClass::MOP::Method::Wrapped::::BEGIN@10Class::MOP::Method::Wrapped::BEGIN@10
1117µs35µsClass::MOP::Method::Wrapped::::BEGIN@13Class::MOP::Method::Wrapped::BEGIN@13
1117µs30µsClass::MOP::Method::Wrapped::::BEGIN@14Class::MOP::Method::Wrapped::BEGIN@14
1116µs46µsClass::MOP::Method::Wrapped::::BEGIN@16Class::MOP::Method::Wrapped::BEGIN@16
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:45]Class::MOP::Method::Wrapped::__ANON__[:45]
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:51]Class::MOP::Method::Wrapped::__ANON__[:51]
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:66]Class::MOP::Method::Wrapped::__ANON__[:66]
0000s0sClass::MOP::Method::Wrapped::::__ANON__[:91]Class::MOP::Method::Wrapped::__ANON__[:91]
0000s0sClass::MOP::Method::Wrapped::::_make_compatible_withClass::MOP::Method::Wrapped::_make_compatible_with
0000s0sClass::MOP::Method::Wrapped::::add_after_modifierClass::MOP::Method::Wrapped::add_after_modifier
0000s0sClass::MOP::Method::Wrapped::::add_before_modifierClass::MOP::Method::Wrapped::add_before_modifier
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
# spent 8µs within Class::MOP::Method::Wrapped::BEGIN@3 which was called: # once (8µs+0s) by Class::MOP::Class::BEGIN@14 at line 5
BEGIN {
415µs $Class::MOP::Method::Wrapped::AUTHORITY = 'cpan:STEVAN';
5129µs18µs}
# spent 8µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@3
6{
721µs $Class::MOP::Method::Wrapped::VERSION = '2.1005';
8}
9
10221µs214µs
# spent 11µs (7+3) within Class::MOP::Method::Wrapped::BEGIN@10 which was called: # once (7µs+3µs) by Class::MOP::Class::BEGIN@14 at line 10
use strict;
# spent 11µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@10 # spent 3µs making 1 call to strict::import
11224µs220µs
# spent 15µs (10+5) within Class::MOP::Method::Wrapped::BEGIN@11 which was called: # once (10µs+5µs) by Class::MOP::Class::BEGIN@14 at line 11
use warnings;
# spent 15µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@11 # spent 5µs making 1 call to warnings::import
12
13225µs262µs
# spent 35µs (7+28) within Class::MOP::Method::Wrapped::BEGIN@13 which was called: # once (7µs+28µs) by Class::MOP::Class::BEGIN@14 at line 13
use Carp 'confess';
# spent 35µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@13 # spent 28µs making 1 call to Exporter::import
14224µs253µs
# spent 30µs (7+23) within Class::MOP::Method::Wrapped::BEGIN@14 which was called: # once (7µs+23µs) by Class::MOP::Class::BEGIN@14 at line 14
use Scalar::Util 'blessed';
# spent 30µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@14 # spent 23µs making 1 call to Exporter::import
15
162823µs285µs
# spent 46µs (6+40) within Class::MOP::Method::Wrapped::BEGIN@16 which was called: # once (6µs+40µs) by Class::MOP::Class::BEGIN@14 at line 16
use base 'Class::MOP::Method';
# spent 46µs making 1 call to Class::MOP::Method::Wrapped::BEGIN@16 # spent 40µs making 1 call to base::import
17
18# NOTE:
19# this ugly beast is the result of trying
20# to micro optimize this as much as possible
21# while not completely loosing maintainability.
22# At this point it's "fast enough", after all
23# you can't get something for nothing :)
24
# spent 276µs within Class::MOP::Method::Wrapped::__ANON__[/usr/local/lib/perl/5.14.2/Class/MOP/Method/Wrapped.pm:71] which was called 92 times, avg 3µs/call: # 46 times (145µs+0s) by Class::MOP::Method::Wrapped::wrap at line 89, avg 3µs/call # 46 times (132µs+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 174, avg 3µs/call
my $_build_wrapped_method = sub {
259221µs my $modifier_table = shift;
269270µs my ($before, $after, $around) = (
27 $modifier_table->{before},
28 $modifier_table->{after},
29 $modifier_table->{around},
30 );
3192223µs if (@$before && @$after) {
32 $modifier_table->{cache} = sub {
33 for my $c (@$before) { $c->(@_) };
34 my @rval;
35 ((defined wantarray) ?
36 ((wantarray) ?
37 (@rval = $around->{cache}->(@_))
38 :
39 ($rval[0] = $around->{cache}->(@_)))
40 :
41 $around->{cache}->(@_));
42 for my $c (@$after) { $c->(@_) };
43 return unless defined wantarray;
44 return wantarray ? @rval : $rval[0];
45 }
46 }
47 elsif (@$before && !@$after) {
48 $modifier_table->{cache} = sub {
49 for my $c (@$before) { $c->(@_) };
50 return $around->{cache}->(@_);
51 }
52 }
53 elsif (@$after && !@$before) {
54 $modifier_table->{cache} = sub {
55 my @rval;
56 ((defined wantarray) ?
57 ((wantarray) ?
58 (@rval = $around->{cache}->(@_))
59 :
60 ($rval[0] = $around->{cache}->(@_)))
61 :
62 $around->{cache}->(@_));
63 for my $c (@$after) { $c->(@_) };
64 return unless defined wantarray;
65 return wantarray ? @rval : $rval[0];
66 }
67 }
68 else {
699238µs $modifier_table->{cache} = $around->{cache};
70 }
7113µs};
72
73
# spent 2.39ms (958µs+1.43) within Class::MOP::Method::Wrapped::wrap which was called 46 times, avg 52µs/call: # 46 times (958µs+1.43ms) by Class::MOP::Class::__ANON__[/usr/local/lib/perl/5.14.2/Class/MOP/Class.pm:1072] at line 1058 of Class/MOP/Class.pm, avg 52µs/call
sub wrap {
744666µs my ( $class, $code, %params ) = @_;
75
7646181µs9253µs (blessed($code) && $code->isa('Class::MOP::Method'))
# spent 27µs making 46 calls to UNIVERSAL::isa, avg 596ns/call # spent 25µs making 46 calls to Scalar::Util::blessed, avg 548ns/call
77 || confess "Can only wrap blessed CODE";
78
7946299µs9241µs my $modifier_table = {
# spent 41µs making 92 calls to Class::MOP::Method::body, avg 450ns/call
80 cache => undef,
81 orig => $code->body,
82 before => [],
83 after => [],
84 around => {
85 cache => $code->body,
86 methods => [],
87 },
88 };
894653µs46145µs $_build_wrapped_method->($modifier_table);
# spent 145µs making 46 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:71], avg 3µs/call
90 return $class->SUPER::wrap(
919812.27ms98119.3ms sub { $modifier_table->{cache}->(@_) },
# spent 19.3ms making 981 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:162], avg 20µs/call
92 # get these from the original
93 # unless explicitly overridden
9446436µs461.19ms package_name => $params{package_name} || $code->package_name,
# spent 1.19ms making 46 calls to Class::MOP::Method::wrap, avg 26µs/call
95 name => $params{name} || $code->name,
96 original_method => $code,
97
98 modifier_table => $modifier_table,
99 );
100}
101
102
# spent 507µs within Class::MOP::Method::Wrapped::_new which was called 46 times, avg 11µs/call: # 46 times (507µs+0s) by Class::MOP::Method::wrap at line 46 of Class/MOP/Method.pm, avg 11µs/call
sub _new {
1034613µs my $class = shift;
104469µs return Class::MOP::Class->initialize($class)->new_object(@_)
105 if $class ne __PACKAGE__;
106
1074618µs my $params = @_ == 1 ? $_[0] : {@_};
108
10946511µs return bless {
110 # inherited from Class::MOP::Method
111 'body' => $params->{body},
112 'associated_metaclass' => $params->{associated_metaclass},
113 'package_name' => $params->{package_name},
114 'name' => $params->{name},
115 'original_method' => $params->{original_method},
116
117 # defined in this class
118 'modifier_table' => $params->{modifier_table}
119 } => $class;
120}
121
122sub get_original_method {
123 my $code = shift;
124 $code->original_method;
125}
126
127sub add_before_modifier {
128 my $code = shift;
129 my $modifier = shift;
130 unshift @{$code->{'modifier_table'}->{before}} => $modifier;
131 $_build_wrapped_method->($code->{'modifier_table'});
132}
133
134sub before_modifiers {
135 my $code = shift;
136 return @{$code->{'modifier_table'}->{before}};
137}
138
139sub add_after_modifier {
140 my $code = shift;
141 my $modifier = shift;
142 push @{$code->{'modifier_table'}->{after}} => $modifier;
143 $_build_wrapped_method->($code->{'modifier_table'});
144}
145
146sub after_modifiers {
147 my $code = shift;
148 return @{$code->{'modifier_table'}->{after}};
149}
150
151{
152 # NOTE:
153 # this is another possible candidate for
154 # optimization as well. There is an overhead
155 # associated with the currying that, if
156 # eliminated might make around modifiers
157 # more manageable.
1589321µs
# spent 255µs within Class::MOP::Method::Wrapped::__ANON__[/usr/local/lib/perl/5.14.2/Class/MOP/Method/Wrapped.pm:164] which was called 46 times, avg 6µs/call: # 46 times (255µs+0s) by Class::MOP::Method::Wrapped::add_around_modifier at line 171, avg 6µs/call
my $compile_around_method = sub {{
159469µs my $f1 = pop;
16092133µs return $f1 unless @_;
161467µs my $f2 = pop;
16210272.35ms98116.9ms
# spent 19.3ms (2.49+16.9) within Class::MOP::Method::Wrapped::__ANON__[/usr/local/lib/perl/5.14.2/Class/MOP/Method/Wrapped.pm:162] which was called 981 times, avg 20µs/call: # 981 times (2.49ms+16.9ms) by Class::MOP::Class::Immutable::Class::MOP::Class::_method_map 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::Moose::Meta::Class::_method_map or Class::MOP::Class::Immutable::Moose::Meta::Class::get_all_attributes or Class::MOP::Class::Immutable::Moose::Meta::Class::get_all_methods or Class::MOP::Class::Immutable::Moose::Meta::Class::get_meta_instance or Class::MOP::Class::Immutable::Moose::Meta::Class::linearized_isa or MongoDB::Connection::new at line 91, avg 20µs/call
push @_, sub { $f2->( $f1, @_ ) };
# spent 16.9ms making 981 calls to Class::MOP::Class:::around, avg 17µs/call
1634613µs redo;
16412µs }};
165
166
# spent 776µs (389+387) within Class::MOP::Method::Wrapped::add_around_modifier which was called 46 times, avg 17µs/call: # 46 times (389µs+387µs) by Class::MOP::Class::add_around_method_modifier at line 1099 of Class/MOP/Class.pm, avg 17µs/call
sub add_around_modifier {
1674611µs my $code = shift;
168465µs my $modifier = shift;
1699273µs unshift @{$code->{'modifier_table'}->{around}->{methods}} => $modifier;
1704619µs $code->{'modifier_table'}->{around}->{cache} = $compile_around_method->(
1714687µs46255µs @{$code->{'modifier_table'}->{around}->{methods}},
# spent 255µs making 46 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:164], avg 6µs/call
172 $code->{'modifier_table'}->{orig}
173 );
17446118µs46132µs $_build_wrapped_method->($code->{'modifier_table'});
# spent 132µs making 46 calls to Class::MOP::Method::Wrapped::__ANON__[Class/MOP/Method/Wrapped.pm:71], avg 3µs/call
175 }
176}
177
178sub around_modifiers {
179 my $code = shift;
180 return @{$code->{'modifier_table'}->{around}->{methods}};
181}
182
183sub _make_compatible_with {
184 my $self = shift;
185 my ($other) = @_;
186
187 # XXX: this is pretty gross. the issue here is that CMOP::Method::Wrapped
188 # objects are subclasses of CMOP::Method, but when we get to moose, they'll
189 # need to be compatible with Moose::Meta::Method, which isn't possible. the
190 # right solution here is to make ::Wrapped into a role that gets applied to
191 # whatever the method_metaclass happens to be and get rid of
192 # wrapped_method_metaclass entirely, but that's not going to happen until
193 # we ditch cmop and get roles into the bootstrapping, so. i'm not
194 # maintaining the previous behavior of turning them into instances of the
195 # new method_metaclass because that's equally broken, and at least this way
196 # any issues will at least be detectable and potentially fixable. -doy
197 return $self unless $other->_is_compatible_with($self->_real_ref_name);
198
199 return $self->SUPER::_make_compatible_with(@_);
200}
201
20214µs1;
203
204# ABSTRACT: Method Meta Object for methods with before/after/around modifiers
205
206__END__