← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:45:08 2010
Reported on Wed Nov 17 22:09:58 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP/Method/Constructor.pm
StatementsExecuted 4739 statements in 61.3ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2651121.4ms104msClass::MOP::Method::Constructor::::_generate_slot_initializerClass::MOP::Method::Constructor::_generate_slot_initializer
311116.3ms183msClass::MOP::Method::Constructor::::_generate_constructor_method_inlineClass::MOP::Method::Constructor::_generate_constructor_method_inline
485838.12ms36.5msClass::MOP::Method::Constructor::::_attributesClass::MOP::Method::Constructor::_attributes
145224.54ms7.27msClass::MOP::Method::Constructor::::_generate_default_valueClass::MOP::Method::Constructor::_generate_default_value
31113.32ms192msClass::MOP::Method::Constructor::::newClass::MOP::Method::Constructor::new
31112.29ms2.29msClass::MOP::Method::Constructor::::_newClass::MOP::Method::Constructor::_new
31111.51ms185msClass::MOP::Method::Constructor::::_initialize_bodyClass::MOP::Method::Constructor::_initialize_body
11173µs93µsClass::MOP::Method::Constructor::::BEGIN@4Class::MOP::Method::Constructor::BEGIN@4
11143µs3.72msClass::MOP::Method::Constructor::::BEGIN@14Class::MOP::Method::Constructor::BEGIN@14
11141µs211µsClass::MOP::Method::Constructor::::BEGIN@7Class::MOP::Method::Constructor::BEGIN@7
11141µs208µsClass::MOP::Method::Constructor::::BEGIN@8Class::MOP::Method::Constructor::BEGIN@8
11140µs109µsClass::MOP::Method::Constructor::::BEGIN@5Class::MOP::Method::Constructor::BEGIN@5
0000s0sClass::MOP::Method::Constructor::::__ANON__[:92]Class::MOP::Method::Constructor::__ANON__[:92]
0000s0sClass::MOP::Method::Constructor::::_generate_constructor_methodClass::MOP::Method::Constructor::_generate_constructor_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::Constructor;
3
43102µs2112µs
# spent 93µs (73+20) within Class::MOP::Method::Constructor::BEGIN@4 which was called: # once (73µs+20µs) by Class::MOP::Class::BEGIN@10 at line 4
use strict;
# spent 93µs making 1 call to Class::MOP::Method::Constructor::BEGIN@4 # spent 20µs making 1 call to strict::import
53104µs2178µs
# spent 109µs (40+69) within Class::MOP::Method::Constructor::BEGIN@5 which was called: # once (40µs+69µs) by Class::MOP::Class::BEGIN@10 at line 5
use warnings;
# spent 109µs making 1 call to Class::MOP::Method::Constructor::BEGIN@5 # spent 69µs making 1 call to warnings::import
6
73139µs2382µs
# spent 211µs (41+170) within Class::MOP::Method::Constructor::BEGIN@7 which was called: # once (41µs+170µs) by Class::MOP::Class::BEGIN@10 at line 7
use Carp 'confess';
# spent 211µs making 1 call to Class::MOP::Method::Constructor::BEGIN@7 # spent 170µs making 1 call to Exporter::import
83232µs2376µs
# spent 208µs (41+168) within Class::MOP::Method::Constructor::BEGIN@8 which was called: # once (41µs+168µs) by Class::MOP::Class::BEGIN@10 at line 8
use Scalar::Util 'blessed', 'weaken';
# spent 208µs making 1 call to Class::MOP::Method::Constructor::BEGIN@8 # spent 168µs making 1 call to Exporter::import
9
1015µsour $VERSION = '1.11';
11162µs$VERSION = eval $VERSION;
# spent 12µs executing statements in string eval
1213µsour $AUTHORITY = 'cpan:STEVAN';
13
1433.42ms23.72ms
# spent 3.72ms (43µs+3.68) within Class::MOP::Method::Constructor::BEGIN@14 which was called: # once (43µs+3.68ms) by Class::MOP::Class::BEGIN@10 at line 14
use base 'Class::MOP::Method::Inlined';
# spent 3.72ms making 1 call to Class::MOP::Method::Constructor::BEGIN@14 # spent 3.68ms making 1 call to base::import, recursion: max depth 1, sum of overlapping time 3.68ms
15
16
# spent 192ms (3.32+188) within Class::MOP::Method::Constructor::new which was called 31 times, avg 6.18ms/call: # 31 times (3.32ms+188ms) by Class::MOP::Class::_inline_constructor at line 1330 of Class/MOP/Class.pm, avg 6.18ms/call
sub new {
172483.81ms my $class = shift;
18 my %options = @_;
19
2062423µs (blessed $options{metaclass} && $options{metaclass}->isa('Class::MOP::Class'))
# spent 223µs making 31 calls to UNIVERSAL::isa, avg 7µs/call # spent 200µs making 31 calls to Scalar::Util::blessed, avg 6µs/call
21 || confess "You must pass a metaclass instance if you want to inline"
22 if $options{is_inline};
23
24 ($options{package_name} && $options{name})
25 || confess "You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT";
26
27312.29ms my $self = $class->_new(\%options);
# spent 2.29ms making 31 calls to Class::MOP::Method::Constructor::_new, avg 74µs/call
28
29 # we don't want this creating
30 # a cycle in the code, if not
31 # needed
3231233µs weaken($self->{'associated_metaclass'});
# spent 233µs making 31 calls to Scalar::Util::weaken, avg 8µs/call
33
3431185ms $self->_initialize_body;
# spent 185ms making 31 calls to Class::MOP::Method::Constructor::_initialize_body, avg 5.98ms/call
35
36 return $self;
37}
38
39
# spent 2.29ms within Class::MOP::Method::Constructor::_new which was called 31 times, avg 74µs/call: # 31 times (2.29ms+0s) by Class::MOP::Method::Constructor::new at line 27, avg 74µs/call
sub _new {
401242.45ms my $class = shift;
41
42 return Class::MOP::Class->initialize($class)->new_object(@_)
43 if $class ne __PACKAGE__;
44
45 my $params = @_ == 1 ? $_[0] : {@_};
46
47 return bless {
48 # inherited from Class::MOP::Method
49 body => $params->{body},
50 # associated_metaclass => $params->{associated_metaclass}, # overriden
51 package_name => $params->{package_name},
52 name => $params->{name},
53 original_method => $params->{original_method},
54
55 # inherited from Class::MOP::Generated
56 is_inline => $params->{is_inline} || 0,
57 definition_context => $params->{definition_context},
58
59 # inherited from Class::MOP::Inlined
60 _expected_method_class => $params->{_expected_method_class},
61
62 # defined in this subclass
63 options => $params->{options} || {},
64 associated_metaclass => $params->{metaclass},
65 }, $class;
66}
67
68## accessors
69
70731.05mssub options { (shift)->{'options'} }
711552.10mssub associated_metaclass { (shift)->{'associated_metaclass'} }
72
73## cached values ...
74
75
# spent 36.5ms (8.12+28.4) within Class::MOP::Method::Constructor::_attributes which was called 485 times, avg 75µs/call: # 130 times (1.57ms+0s) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 222 of Moose/Meta/Method/Constructor.pm, avg 12µs/call # 130 times (1.44ms+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 194 of Moose/Meta/Method/Constructor.pm, avg 11µs/call # 42 times (1.88ms+14.9ms) by Moose::Meta::Method::Constructor::_generate_slot_initializers at line 140 of Moose/Meta/Method/Constructor.pm, avg 401µs/call # 42 times (519µs+0s) by Moose::Meta::Method::Constructor::_generate_triggers at line 193 of Moose/Meta/Method/Constructor.pm, avg 12µs/call # 42 times (487µs+0s) by Moose::Meta::Method::Constructor::_initialize_body at line 89 of Moose/Meta/Method/Constructor.pm, avg 12µs/call # 37 times (519µs+0s) by Class::MOP::Class:::around at line 25 of MooseX/StrictConstructor/Role/Meta/Method/Constructor.pm, avg 14µs/call # 31 times (1.33ms+13.5ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 98, avg 477µs/call # 31 times (369µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 116, avg 12µs/call
sub _attributes {
769709.66ms my $self = shift;
7714628.4ms $self->{'attributes'} ||= [ $self->associated_metaclass->get_all_attributes ]
# spent 27.8ms making 73 calls to Class::MOP::Class::get_all_attributes, avg 381µs/call # spent 342µs making 42 calls to Class::MOP::Method::associated_metaclass, avg 8µs/call # spent 281µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call
78}
79
80## method
81
82
# spent 185ms (1.51+184) within Class::MOP::Method::Constructor::_initialize_body which was called 31 times, avg 5.98ms/call: # 31 times (1.51ms+184ms) by Class::MOP::Method::Constructor::new at line 34, avg 5.98ms/call
sub _initialize_body {
831241.37ms my $self = shift;
84 my $method_name = '_generate_constructor_method';
85
8631319µs $method_name .= '_inline' if $self->is_inline;
# spent 319µs making 31 calls to Class::MOP::Method::Generated::is_inline, avg 10µs/call
87
8831183ms $self->{'body'} = $self->$method_name;
# spent 183ms making 31 calls to Class::MOP::Method::Constructor::_generate_constructor_method_inline, avg 5.92ms/call
89}
90
91sub _generate_constructor_method {
92 return sub { Class::MOP::Class->initialize(shift)->new_object(@_) }
93}
94
95
# spent 183ms (16.3+167) within Class::MOP::Method::Constructor::_generate_constructor_method_inline which was called 31 times, avg 5.92ms/call: # 31 times (16.3ms+167ms) by Class::MOP::Method::Constructor::_initialize_body at line 88, avg 5.92ms/call
sub _generate_constructor_method_inline {
96108814.1ms my $self = shift;
97
9829618.4ms my $defaults = [map { $_->default } @{ $self->_attributes }];
# spent 14.8ms making 31 calls to Class::MOP::Method::Constructor::_attributes, avg 477µs/call # spent 3.64ms making 265 calls to Class::MOP::Mixin::AttributeCore::default, avg 14µs/call
99
100 my $close_over = {
101 '$defaults' => \$defaults,
102 };
103
104 my $source = 'sub {';
105 $source .= "\n" . 'my $class = shift;';
106
107 $source .= "\n" . 'return Class::MOP::Class->initialize($class)->new_object(@_)';
10862481µs $source .= "\n" . ' if $class ne \'' . $self->associated_metaclass->name . '\';';
# spent 293µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call # spent 189µs making 31 calls to Class::MOP::Package::name, avg 6µs/call
109
110 $source .= "\n" . 'my $params = @_ == 1 ? $_[0] : {@_};';
111
1126210.0ms $source .= "\n" . 'my $instance = ' . $self->associated_metaclass->inline_create_instance('$class');
# spent 9.74ms making 31 calls to Class::MOP::Class::inline_create_instance, avg 314µs/call # spent 264µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 9µs/call
113 my $idx = 0;
114265104ms $source .= ";\n" . (join ";\n" => map {
# spent 104ms making 265 calls to Class::MOP::Method::Constructor::_generate_slot_initializer, avg 392µs/call
115 $self->_generate_slot_initializer($_, $idx++)
11631369µs } @{ $self->_attributes });
# spent 369µs making 31 calls to Class::MOP::Method::Constructor::_attributes, avg 12µs/call
117931.34ms if (Class::MOP::metaclass_is_weak($self->associated_metaclass->name)) {
# spent 806µs making 31 calls to Class::MOP::metaclass_is_weak, avg 26µs/call # spent 333µs making 31 calls to Class::MOP::Method::Constructor::associated_metaclass, avg 11µs/call # spent 198µs making 31 calls to Class::MOP::Package::name, avg 6µs/call
118 $source .= ";\n" . $self->associated_metaclass->_inline_set_mop_slot('$instance', 'Class::MOP::class_of($class)');
119 }
120 $source .= ";\n" . 'return $instance';
121 $source .= ";\n" . '}';
12231355µs warn $source if $self->options->{debug};
# spent 355µs making 31 calls to Class::MOP::Method::Constructor::options, avg 11µs/call
123
1243132.2ms my ( $code, $e ) = $self->_eval_closure(
# spent 32.2ms making 31 calls to Class::MOP::Method::Generated::_eval_closure, avg 1.04ms/call
125 $close_over,
126 $source
127 );
128 confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$e" if $e;
129
130 return $code;
131}
132
133
# spent 104ms (21.4+82.6) within Class::MOP::Method::Constructor::_generate_slot_initializer which was called 265 times, avg 392µs/call: # 265 times (21.4ms+82.6ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 114, avg 392µs/call
sub _generate_slot_initializer {
134159118.3ms my $self = shift;
135 my $attr = shift;
136 my $idx = shift;
137
138 my $default;
1395308.90ms if ($attr->has_default) {
# spent 4.49ms making 87 calls to Class::MOP::Method::Constructor::_generate_default_value, avg 52µs/call # spent 2.62ms making 265 calls to Class::MOP::Mixin::AttributeCore::has_default, avg 10µs/call # spent 1.78ms making 178 calls to Class::MOP::Mixin::AttributeCore::has_builder, avg 10µs/call
140 $default = $self->_generate_default_value($attr, $idx);
141 } elsif( $attr->has_builder ) {
142 $default = '$instance->'.$attr->builder;
143 }
144
14560673.7ms if ( defined( my $init_arg = $attr->init_arg ) ) {
# spent 69.8ms making 339 calls to Class::MOP::Attribute::inline_set, avg 206µs/call # spent 2.66ms making 265 calls to Class::MOP::Mixin::AttributeCore::init_arg, avg 10µs/call # spent 1.19ms making 2 calls to Moose::Meta::Attribute::inline_set, avg 595µs/call
146 return (
147 'if(exists $params->{\''
148 . $init_arg . '\'}){' . "\n"
149 . $attr->inline_set(
150 '$instance',
151 '$params->{\'' . $init_arg . '\'}'
152 )
153 . "\n" . '} '
154 . (
155 !defined $default ? '' : 'else {' . "\n"
156 . $attr->inline_set(
157 '$instance',
158 $default
159 )
160 . "\n" . '}'
161 )
162 );
163 }
164 elsif ( defined $default ) {
165 return (
166 $attr->inline_set(
167 '$instance',
168 $default
169 )
170 . "\n"
171 );
172 }
173 else {
174 return '';
175 }
176}
177
178
# spent 7.27ms (4.54+2.73) within Class::MOP::Method::Constructor::_generate_default_value which was called 145 times, avg 50µs/call: # 87 times (2.75ms+1.74ms) by Class::MOP::Method::Constructor::_generate_slot_initializer at line 139, avg 52µs/call # 58 times (1.79ms+991µs) by Moose::Meta::Method::Constructor::_generate_slot_initializer at line 244 of Moose/Meta/Method/Constructor.pm, avg 48µs/call
sub _generate_default_value {
1793474.39ms my ($self, $attr, $index) = @_;
180 # NOTE:
181 # default values can either be CODE refs
182 # in which case we need to call them. Or
183 # they can be scalars (strings/numbers)
184 # in which case we can just deal with them
185 # in the code we eval.
1861452.73ms if ($attr->is_default_a_coderef) {
# spent 2.73ms making 145 calls to Class::MOP::Mixin::AttributeCore::is_default_a_coderef, avg 19µs/call
187 return '$defaults->[' . $index . ']->($instance)';
188 }
189 else {
190 return '$defaults->[' . $index . ']';
191 }
192}
193
194113µs1;
195
196__END__