← Index
NYTProf Performance Profile   « line view »
For /home/ss5/perl5/perlbrew/perls/perl-5.22.0/bin/benchmarkanything-storage
  Run on Mon Jan 29 16:55:34 2018
Reported on Mon Jan 29 16:57:07 2018

Filename/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Method/Generate/Constructor.pm
StatementsExecuted 2420 statements in 3.22ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1011458µs1.95msMethod::Generate::Constructor::::_assign_newMethod::Generate::Constructor::_assign_new
4343395µs660µsMethod::Generate::Constructor::::register_attribute_specsMethod::Generate::Constructor::register_attribute_specs
1011324µs3.66msMethod::Generate::Constructor::::generate_methodMethod::Generate::Constructor::generate_method
211323µs451µsMethod::Generate::Constructor::::buildall_generatorMethod::Generate::Constructor::buildall_generator
1011229µs274µsMethod::Generate::Constructor::::_check_requiredMethod::Generate::Constructor::_check_required
5421148µs304µsMethod::Generate::Constructor::::assert_constructorMethod::Generate::Constructor::assert_constructor
1111127µs448µsMethod::Generate::Constructor::::install_delayedMethod::Generate::Constructor::install_delayed
1011104µs7.37msMethod::Generate::Constructor::::__ANON__[:97]Method::Generate::Constructor::__ANON__[:97]
5411103µs156µsMethod::Generate::Constructor::::current_constructorMethod::Generate::Constructor::current_constructor
711185µs85µsMethod::Generate::Constructor::::_cap_callMethod::Generate::Constructor::_cap_call
101154µs70µsMethod::Generate::Constructor::::_build_construction_stringMethod::Generate::Constructor::_build_construction_string
101147µs91µsMethod::Generate::Constructor::::_handle_subconstructorMethod::Generate::Constructor::_handle_subconstructor
303134µs34µsMethod::Generate::Constructor::::CORE:sortMethod::Generate::Constructor::CORE:sort (opcode)
101132µs102µsMethod::Generate::Constructor::::construction_stringMethod::Generate::Constructor::construction_string
393119µs19µsMethod::Generate::Constructor::::accessor_generatorMethod::Generate::Constructor::accessor_generator
821110µs10µsMethod::Generate::Constructor::::CORE:substMethod::Generate::Constructor::CORE:subst (opcode)
101110µs10µsMethod::Generate::Constructor::::all_attribute_specsMethod::Generate::Constructor::all_attribute_specs
7119µs9µsMethod::Generate::Constructor::::_generate_argsMethod::Generate::Constructor::_generate_args
1118µs17µsMethod::Generate::Constructor::::BEGIN@3Method::Generate::Constructor::BEGIN@3
1115µs27µsMethod::Generate::Constructor::::BEGIN@4Method::Generate::Constructor::BEGIN@4
3115µs5µsMethod::Generate::Constructor::::_generate_args_via_buildargsMethod::Generate::Constructor::_generate_args_via_buildargs
1115µs20µsMethod::Generate::Constructor::::BEGIN@5Method::Generate::Constructor::BEGIN@5
1114µs4.74msMethod::Generate::Constructor::::BEGIN@7Method::Generate::Constructor::BEGIN@7
1114µs17µsMethod::Generate::Constructor::::BEGIN@6Method::Generate::Constructor::BEGIN@6
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Method::Generate::Constructor;
2
3223µs227µs
# spent 17µs (8+10) within Method::Generate::Constructor::BEGIN@3 which was called: # once (8µs+10µs) by Moo::_constructor_maker_for at line 3
use Moo::_strictures;
# spent 17µs making 1 call to Method::Generate::Constructor::BEGIN@3 # spent 10µs making 1 call to Moo::_strictures::import
4215µs249µs
# spent 27µs (5+22) within Method::Generate::Constructor::BEGIN@4 which was called: # once (5µs+22µs) by Moo::_constructor_maker_for at line 4
use Sub::Quote qw(quote_sub unquote_sub quotify);
# spent 27µs making 1 call to Method::Generate::Constructor::BEGIN@4 # spent 22µs making 1 call to Exporter::import
5214µs236µs
# spent 20µs (5+15) within Method::Generate::Constructor::BEGIN@5 which was called: # once (5µs+15µs) by Moo::_constructor_maker_for at line 5
use Sub::Defer;
# spent 20µs making 1 call to Method::Generate::Constructor::BEGIN@5 # spent 16µs making 1 call to Exporter::import
6212µs229µs
# spent 17µs (4+13) within Method::Generate::Constructor::BEGIN@6 which was called: # once (4µs+13µs) by Moo::_constructor_maker_for at line 6
use Moo::_Utils qw(_getstash _getglob);
# spent 17µs making 1 call to Method::Generate::Constructor::BEGIN@6 # spent 13µs making 1 call to Exporter::import
72923µs29.47ms
# spent 4.74ms (4µs+4.73) within Method::Generate::Constructor::BEGIN@7 which was called: # once (4µs+4.73ms) by Moo::_constructor_maker_for at line 7
use Moo;
# spent 4.74ms making 1 call to Method::Generate::Constructor::BEGIN@7 # spent 4.73ms making 1 call to Moo::import
8
9
# spent 660µs (395+265) within Method::Generate::Constructor::register_attribute_specs which was called 43 times, avg 15µs/call: # 21 times (122µs+111µs) by Moo::has at line 55 of Moo.pm, avg 11µs/call # 11 times (58µs+59µs) by Moo::_constructor_maker_for at line 211 of Moo.pm, avg 11µs/call # 10 times (197µs+89µs) by Moo::Role::_handle_constructor at line 406 of Moo/Role.pm, avg 29µs/call # once (18µs+5µs) by Moo::_constructor_maker_for at line 245
sub register_attribute_specs {
104319µs my ($self, @new_specs) = @_;
114326µs43220µs $self->assert_constructor;
# spent 220µs making 43 calls to Method::Generate::Constructor::assert_constructor, avg 5µs/call
124314µs my $specs = $self->{attribute_specs}||={};
134370µs while (my ($name, $new_spec) = splice @new_specs, 0, 2) {
148289µs8210µs if ($name =~ s/^\+//) {
# spent 10µs making 82 calls to Method::Generate::Constructor::CORE:subst, avg 123ns/call
15 die "has '+${name}' given but no ${name} attribute already exists"
16 unless my $old_spec = $specs->{$name};
17 foreach my $key (keys %$old_spec) {
18 if (!exists $new_spec->{$key}) {
19 $new_spec->{$key} = $old_spec->{$key}
20 unless $key eq 'handles';
21 }
22 elsif ($key eq 'moosify') {
23 $new_spec->{$key} = [
24 map { ref $_ eq 'ARRAY' ? @$_ : $_ }
25 ($old_spec->{$key}, $new_spec->{$key})
26 ];
27 }
28 }
29 }
308243µs3834µs if ($new_spec->{required}
# spent 25µs making 19 calls to Method::Generate::Accessor::has_default, avg 1µs/call # spent 9µs making 19 calls to Method::Generate::Constructor::accessor_generator, avg 489ns/call
31 && !(
32 $self->accessor_generator->has_default($name, $new_spec)
33 || !exists $new_spec->{init_arg}
34 || defined $new_spec->{init_arg}
35 )
36 ) {
37 die "You cannot have a required attribute (${name})"
38 . " without a default, builder, or an init_arg";
39 }
40 $new_spec->{index} = scalar keys %$specs
418230µs unless defined $new_spec->{index};
428232µs $specs->{$name} = $new_spec;
43 }
444352µs $self;
45}
46
47
# spent 10µs within Method::Generate::Constructor::all_attribute_specs which was called 10 times, avg 970ns/call: # 10 times (10µs+0s) by Moo::Role::_handle_constructor at line 398 of Moo/Role.pm, avg 970ns/call
sub all_attribute_specs {
48 $_[0]->{attribute_specs}
491017µs}
50
51
# spent 19µs within Method::Generate::Constructor::accessor_generator which was called 39 times, avg 490ns/call: # 19 times (9µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 30, avg 489ns/call # 10 times (7µs+0s) by Method::Generate::Constructor::_build_construction_string at line 69, avg 670ns/call # 10 times (3µs+0s) by Method::Generate::Constructor::_assign_new at line 205, avg 310ns/call
sub accessor_generator {
52 $_[0]->{accessor_generator}
533949µs}
54
55
# spent 102µs (32+70) within Method::Generate::Constructor::construction_string which was called 10 times, avg 10µs/call: # 10 times (32µs+70µs) by Method::Generate::Constructor::generate_method at line 138, avg 10µs/call
sub construction_string {
56102µs my ($self) = @_;
57 $self->{construction_string}
581030µs1070µs ||= $self->_build_construction_string;
# spent 70µs making 10 calls to Method::Generate::Constructor::_build_construction_string, avg 7µs/call
59}
60
61
# spent 451µs (323+128) within Method::Generate::Constructor::buildall_generator which was called 2 times, avg 225µs/call: # 2 times (323µs+128µs) by Method::Generate::Constructor::generate_method at line 140, avg 225µs/call
sub buildall_generator {
62250µs require Method::Generate::BuildAll;
6329µs224µs Method::Generate::BuildAll->new;
# spent 24µs making 2 calls to Moo::Object::new, avg 12µs/call
64}
65
66
# spent 70µs (54+15) within Method::Generate::Constructor::_build_construction_string which was called 10 times, avg 7µs/call: # 10 times (54µs+15µs) by Method::Generate::Constructor::construction_string at line 58, avg 7µs/call
sub _build_construction_string {
67103µs my ($self) = @_;
68103µs my $builder = $self->{construction_builder};
691039µs2015µs $builder ? $self->$builder
# spent 9µs making 10 calls to Method::Generate::Accessor::default_construction_string, avg 860ns/call # spent 7µs making 10 calls to Method::Generate::Constructor::accessor_generator, avg 670ns/call
70 : 'bless('
71 .$self->accessor_generator->default_construction_string
72 .', $class);'
73}
74
75
# spent 448µs (127+320) within Method::Generate::Constructor::install_delayed which was called 11 times, avg 41µs/call: # 11 times (127µs+320µs) by Moo::_constructor_maker_for at line 211 of Moo.pm, avg 41µs/call
sub install_delayed {
76115µs my ($self) = @_;
771117µs1184µs $self->assert_constructor;
# spent 84µs making 11 calls to Method::Generate::Constructor::assert_constructor, avg 8µs/call
78115µs my $package = $self->{package};
791125µs114µs my (undef, @isa) = @{mro::get_linear_isa($package)};
# spent 4µs making 11 calls to mro::get_linear_isa, avg 364ns/call
801111µs my $isa = join ',', @isa;
81
# spent 7.37ms (104µs+7.27) within Method::Generate::Constructor::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Method/Generate/Constructor.pm:97] which was called 10 times, avg 737µs/call: # 10 times (104µs+7.27ms) by Sub::Defer::undefer_sub at line 23 of Sub/Defer.pm, avg 737µs/call
$self->{deferred_constructor} = defer_sub "${package}::new" => sub {
821038µs108µs my (undef, @new_isa) = @{mro::get_linear_isa($package)};
# spent 8µs making 10 calls to mro::get_linear_isa, avg 750ns/call
831011µs if (join(',', @new_isa) ne $isa) {
84 my ($expected_new) = grep { *{_getglob($_.'::new')}{CODE} } @isa;
85 my ($found_new) = grep { *{_getglob($_.'::new')}{CODE} } @new_isa;
86 if (($found_new||'') ne ($expected_new||'')) {
87 $found_new ||= 'none';
88 $expected_new ||= 'none';
89 die "Expected parent constructor of $package expected to be"
90 . " $expected_new, but found $found_new: changing the inheritance"
91 . " chain (\@ISA) at runtime is unsupported";
92 }
93 }
94 unquote_sub $self->generate_method(
951074µs207.26ms $package, 'new', $self->{attribute_specs}, { no_install => 1 }
# spent 3.66ms making 10 calls to Method::Generate::Constructor::generate_method, avg 366µs/call # spent 3.60ms making 10 calls to Sub::Quote::unquote_sub, avg 360µs/call
96 )
971145µs11233µs };
# spent 233µs making 11 calls to Sub::Defer::defer_sub, avg 21µs/call
981117µs $self;
99}
100
101
# spent 156µs (103+53) within Method::Generate::Constructor::current_constructor which was called 54 times, avg 3µs/call: # 54 times (103µs+53µs) by Method::Generate::Constructor::assert_constructor at line 109, avg 3µs/call
sub current_constructor {
1025410µs my ($self, $package) = @_;
1035499µs5453µs return *{_getglob("${package}::new")}{CODE};
# spent 53µs making 54 calls to Moo::_Utils::_getglob, avg 981ns/call
104}
105
106
# spent 304µs (148+156) within Method::Generate::Constructor::assert_constructor which was called 54 times, avg 6µs/call: # 43 times (107µs+113µs) by Method::Generate::Constructor::register_attribute_specs at line 11, avg 5µs/call # 11 times (40µs+44µs) by Method::Generate::Constructor::install_delayed at line 77, avg 8µs/call
sub assert_constructor {
107548µs my ($self) = @_;
1085416µs my $package = $self->{package} or return 1;
1095455µs54156µs my $current = $self->current_constructor($package)
# spent 156µs making 54 calls to Method::Generate::Constructor::current_constructor, avg 3µs/call
110 or return 1;
111 my $deferred = $self->{deferred_constructor}
1124310µs or die "Unknown constructor for $package already exists";
1134358µs return 1
114 if $deferred == $current;
115 my $current_deferred = (Sub::Defer::defer_info($current)||[])->[3];
116 if ($current_deferred && $current_deferred == $deferred) {
117 die "Constructor for $package has been inlined and cannot be updated";
118 }
119 die "Constructor for $package has been replaced with an unknown sub";
120}
121
122
# spent 3.66ms (324µs+3.34) within Method::Generate::Constructor::generate_method which was called 10 times, avg 366µs/call: # 10 times (324µs+3.34ms) by Method::Generate::Constructor::__ANON__[/home/ss5/perl5/perlbrew/perls/perl-5.22.0/lib/site_perl/5.22.0/Method/Generate/Constructor.pm:97] at line 95, avg 366µs/call
sub generate_method {
123105µs my ($self, $into, $name, $spec, $quote_opts) = @_;
1241038µs foreach my $no_init (grep !exists($spec->{$_}{init_arg}), keys %$spec) {
1257121µs $spec->{$no_init}{init_arg} = $no_init;
126 }
1271011µs local $self->{captures} = {};
128105µs my $body = ' my $class = shift;'."\n"
129 .' $class = ref($class) if ref($class);'."\n";
1301014µs1091µs $body .= $self->_handle_subconstructor($into, $name);
# spent 91µs making 10 calls to Method::Generate::Constructor::_handle_subconstructor, avg 9µs/call
1311034µs1018µs my $into_buildargs = $into->can('BUILDARGS');
# spent 18µs making 10 calls to UNIVERSAL::can, avg 2µs/call
1321017µs35µs if ( $into_buildargs && $into_buildargs != \&Moo::Object::BUILDARGS ) {
# spent 5µs making 3 calls to Method::Generate::Constructor::_generate_args_via_buildargs, avg 2µs/call
133 $body .= $self->_generate_args_via_buildargs;
134 } else {
135711µs79µs $body .= $self->_generate_args;
# spent 9µs making 7 calls to Method::Generate::Constructor::_generate_args, avg 1µs/call
136 }
1371017µs10274µs $body .= $self->_check_required($spec);
# spent 274µs making 10 calls to Method::Generate::Constructor::_check_required, avg 27µs/call
1381018µs10102µs $body .= ' my $new = '.$self->construction_string.";\n";
# spent 102µs making 10 calls to Method::Generate::Constructor::construction_string, avg 10µs/call
1391022µs101.95ms $body .= $self->_assign_new($spec);
# spent 1.95ms making 10 calls to Method::Generate::Constructor::_assign_new, avg 195µs/call
1401051µs14503µs if ($into->can('BUILD')) {
# spent 451µs making 2 calls to Method::Generate::Constructor::buildall_generator, avg 225µs/call # spent 27µs making 2 calls to Method::Generate::BuildAll::buildall_body_for, avg 14µs/call # spent 25µs making 10 calls to UNIVERSAL::can, avg 3µs/call
141 $body .= $self->buildall_generator->buildall_body_for(
142 $into, '$new', '$args'
143 );
144 }
145104µs $body .= ' return $new;'."\n";
1461030µs1016µs if ($into->can('DEMOLISH')) {
# spent 16µs making 10 calls to UNIVERSAL::can, avg 2µs/call
147 require Method::Generate::DemolishAll;
148 Method::Generate::DemolishAll->new->generate_method($into);
149 }
150 quote_sub
151 "${into}::${name}" => $body,
1521042µs10370µs $self->{captures}, $quote_opts||{}
# spent 370µs making 10 calls to Sub::Quote::quote_sub, avg 37µs/call
153 ;
154}
155
156
# spent 91µs (47+44) within Method::Generate::Constructor::_handle_subconstructor which was called 10 times, avg 9µs/call: # 10 times (47µs+44µs) by Method::Generate::Constructor::generate_method at line 130, avg 9µs/call
sub _handle_subconstructor {
157103µs my ($self, $into, $name) = @_;
1581043µs1044µs if (my $gen = $self->{subconstructor_handler}) {
# spent 44µs making 10 calls to Sub::Quote::quotify, avg 4µs/call
159 ' if ($class ne '.quotify($into).') {'."\n".
160 $gen.
161 ' }'."\n";
162 } else {
163 ''
164 }
165}
166
167
# spent 85µs within Method::Generate::Constructor::_cap_call which was called 71 times, avg 1µs/call: # 71 times (85µs+0s) by Method::Generate::Constructor::_assign_new at line 219, avg 1µs/call
sub _cap_call {
1687113µs my ($self, $code, $captures) = @_;
1697146µs @{$self->{captures}}{keys %$captures} = values %$captures if $captures;
1707165µs $code;
171}
172
173
# spent 5µs within Method::Generate::Constructor::_generate_args_via_buildargs which was called 3 times, avg 2µs/call: # 3 times (5µs+0s) by Method::Generate::Constructor::generate_method at line 132, avg 2µs/call
sub _generate_args_via_buildargs {
1743700ns my ($self) = @_;
17536µs q{ my $args = $class->BUILDARGS(@_);}."\n"
176 .q{ die "BUILDARGS did not return a hashref" unless ref($args) eq 'HASH';}
177 ."\n";
178}
179
180# inlined from Moo::Object - update that first.
181
# spent 9µs within Method::Generate::Constructor::_generate_args which was called 7 times, avg 1µs/call: # 7 times (9µs+0s) by Method::Generate::Constructor::generate_method at line 135, avg 1µs/call
sub _generate_args {
18272µs my ($self) = @_;
183711µs return <<'_EOA';
184 my $args;
185 if ( scalar @_ == 1 ) {
186 unless ( defined $_[0] && ref $_[0] eq 'HASH' ) {
187 die "Single parameters to new() must be a HASH ref"
188 ." data => ". $_[0] ."\n";
189 }
190 $args = { %{ $_[0] } };
191 }
192 elsif ( @_ % 2 ) {
193 die "The new() method for $class expects a hash reference or a"
194 . " key/value list. You passed an odd number of arguments\n";
195 }
196 else {
197 $args = {@_};
198 }
199_EOA
200
201}
202
203
# spent 1.95ms (458µs+1.49) within Method::Generate::Constructor::_assign_new which was called 10 times, avg 195µs/call: # 10 times (458µs+1.49ms) by Method::Generate::Constructor::generate_method at line 139, avg 195µs/call
sub _assign_new {
204103µs my ($self, $spec) = @_;
205108µs103µs my $ag = $self->accessor_generator;
# spent 3µs making 10 calls to Method::Generate::Constructor::accessor_generator, avg 310ns/call
206102µs my %test;
2071030µs108µs NAME: foreach my $name (sort keys %$spec) {
# spent 8µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 770ns/call
2087811µs my $attr_spec = $spec->{$name};
209 next NAME unless defined($attr_spec->{init_arg})
2107814µs74µs or $ag->has_eager_default($name, $attr_spec);
# spent 4µs making 7 calls to Method::Generate::Accessor::has_eager_default, avg 643ns/call
2117129µs $test{$name} = $attr_spec->{init_arg};
212 }
213 join '', map {
21481117µs8199µs my $arg_key = quotify($test{$_});
# spent 92µs making 71 calls to Sub::Quote::quotify, avg 1µs/call # spent 7µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 740ns/call
2157128µs my $test = "exists \$args->{$arg_key}";
2167112µs my $source = "\$args->{$arg_key}";
2177112µs my $attr_spec = $spec->{$_};
218 $self->_cap_call($ag->generate_populate_set(
2197187µs1421.37ms '$new', $_, $attr_spec, $source, $test, $test{$_},
# spent 1.29ms making 71 calls to Method::Generate::Accessor::generate_populate_set, avg 18µs/call # spent 85µs making 71 calls to Method::Generate::Constructor::_cap_call, avg 1µs/call
220 ));
221 } sort keys %test;
222}
223
224
# spent 274µs (229+45) within Method::Generate::Constructor::_check_required which was called 10 times, avg 27µs/call: # 10 times (229µs+45µs) by Method::Generate::Constructor::generate_method at line 137, avg 27µs/call
sub _check_required {
225103µs my ($self, $spec) = @_;
226 my @required_init =
227 map $spec->{$_}{init_arg},
228 grep {
22988163µs1019µs my %s = %{$spec->{$_}}; # ignore required if default or builder set
# spent 19µs making 10 calls to Method::Generate::Constructor::CORE:sort, avg 2µs/call
230 $s{required} and not($s{builder} or exists $s{default})
2317834µs } sort keys %$spec;
2321010µs return '' unless @required_init;
233732µs1926µs ' if (my @missing = grep !exists $args->{$_}, '
# spent 26µs making 19 calls to Sub::Quote::quotify, avg 1µs/call
234 .join(', ', map quotify($_), @required_init).') {'."\n"
235 .q{ die "Missing required arguments: ".join(', ', sort @missing);}."\n"
236 ." }\n";
237}
238
239# bootstrap our own constructor
240sub new {
2411300ns my $class = shift;
24214µs12µs delete _getstash(__PACKAGE__)->{new};
# spent 2µs making 1 call to Moo::_Utils::_getstash
24317µs12µs bless $class->BUILDARGS(@_), $class;
# spent 2µs making 1 call to Moo::Object::BUILDARGS
244}
24519µs222µsMoo->_constructor_maker_for(__PACKAGE__)
# spent 22µs making 1 call to Method::Generate::Constructor::register_attribute_specs # spent 3.79ms making 1 call to Moo::_constructor_maker_for, recursion: max depth 1, sum of overlapping time 3.79ms
246->register_attribute_specs(
247 attribute_specs => {
248 is => 'ro',
249 reader => 'all_attribute_specs',
250 },
251 accessor_generator => { is => 'ro' },
252 construction_string => { is => 'lazy' },
253 construction_builder => { is => 'bare' },
254 subconstructor_handler => { is => 'ro' },
255 package => { is => 'bare' },
256);
257
25814µs1;
 
# spent 34µs within Method::Generate::Constructor::CORE:sort which was called 30 times, avg 1µs/call: # 10 times (19µs+0s) by Method::Generate::Constructor::_check_required at line 229, avg 2µs/call # 10 times (8µs+0s) by Method::Generate::Constructor::_assign_new at line 207, avg 770ns/call # 10 times (7µs+0s) by Method::Generate::Constructor::_assign_new at line 214, avg 740ns/call
sub Method::Generate::Constructor::CORE:sort; # opcode
# spent 10µs within Method::Generate::Constructor::CORE:subst which was called 82 times, avg 123ns/call: # 82 times (10µs+0s) by Method::Generate::Constructor::register_attribute_specs at line 14, avg 123ns/call
sub Method::Generate::Constructor::CORE:subst; # opcode