Profile of Exporter/Heavy.pm

← Index
NYTProf Performance Profile «line view»
For t/bug-md-11.t
Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

Filename | /home/micha/.plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/Exporter/Heavy.pm
Statements | Executed 1119 statements in 2.23ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
12 | 1 | 1 | 959µs | 1.08ms | Exporter::Heavy::::heavy_exportExporter::Heavy::heavy_export
1 | 1 | 1 | 51µs | 57µs | Exporter::Heavy::::_rebuild_cacheExporter::Heavy::_rebuild_cache
2 | 2 | 1 | 30µs | 30µs | Exporter::Heavy::::_push_tagsExporter::Heavy::_push_tags
3 | 1 | 1 | 15µs | 161µs | Exporter::Heavy::::heavy_export_to_levelExporter::Heavy::heavy_export_to_level
1 | 1 | 1 | 10µs | 12µs | Exporter::Heavy::::BEGIN@3Exporter::Heavy::BEGIN@3
1 | 1 | 1 | 6µs | 21µs | Exporter::Heavy::::BEGIN@202Exporter::Heavy::BEGIN@202
1 | 1 | 1 | 4µs | 8µs | Exporter::Heavy::::BEGIN@4Exporter::Heavy::BEGIN@4
1 | 1 | 1 | 4µs | 14µs | Exporter::Heavy::::heavy_export_tagsExporter::Heavy::heavy_export_tags
1 | 1 | 1 | 4µs | 24µs | Exporter::Heavy::::heavy_export_ok_tagsExporter::Heavy::heavy_export_ok_tags
0 | 0 | 0 | 0s | 0s | Exporter::Heavy::::__ANON__[:57]Exporter::Heavy::__ANON__[:57]
0 | 0 | 0 | 0s | 0s | Exporter::Heavy::::__ANON__[:63]Exporter::Heavy::__ANON__[:63]
0 | 0 | 0 | 0s | 0s | Exporter::Heavy::::heavy_require_versionExporter::Heavy::heavy_require_version

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Exporter::Heavy;
2 |  |  |  |  |
3 | 2 | 22µs | 2 | 13µs | # spent 12µs (10+2) within Exporter::Heavy::BEGIN@3 which was called: # once (10µs+2µs) by Exporter::as_heavy at line 3 use strict; # spent 12µs making 1 call to Exporter::Heavy::BEGIN@3 # spent 2µs making 1 call to strict::import
4 | 2 | 757µs | 2 | 12µs | # spent 8µs (4+4) within Exporter::Heavy::BEGIN@4 which was called: # once (4µs+4µs) by Exporter::as_heavy at line 4 no strict 'refs'; # spent 8µs making 1 call to Exporter::Heavy::BEGIN@4 # spent 4µs making 1 call to strict::unimport
5 |  |  |  |  |
6 |  |  |  |  | # On one line so MakeMaker will see it.
7 | 1 | 400ns |  |  | our $VERSION = '5.78';
8 |  |  |  |  |
9 |  |  |  |  | =head1 NAME
10 |  |  |  |  |
11 |  |  |  |  | Exporter::Heavy - Exporter guts
12 |  |  |  |  |
13 |  |  |  |  | =head1 SYNOPSIS
14 |  |  |  |  |
15 |  |  |  |  | (internal use only)
16 |  |  |  |  |
17 |  |  |  |  | =head1 DESCRIPTION
18 |  |  |  |  |
19 |  |  |  |  | No user-serviceable parts inside.
20 |  |  |  |  |
21 |  |  |  |  | =cut
22 |  |  |  |  |
23 |  |  |  |  | #
24 |  |  |  |  | # We go to a lot of trouble not to 'require Carp' at file scope,
25 |  |  |  |  | # because Carp requires Exporter, and something has to give.
26 |  |  |  |  | #
27 |  |  |  |  |
28 |  |  |  |  | # spent 57µs (51+6) within Exporter::Heavy::_rebuild_cache which was called: # once (51µs+6µs) by Exporter::Heavy::heavy_export at line 72 sub _rebuild_cache {
29 | 1 | 300ns |  |  | my ($pkg, $exports, $cache) = @_;
30 | 1 | 700ns |  |  | s/^&// foreach @$exports;
31 | 1 | 800ns |  |  | @{$cache}{@$exports} = (1) x @$exports;
32 | 1 | 900ns |  |  | my $ok = \@{"${pkg}::EXPORT_OK"};
33 | 1 | 2µs |  |  | if (@$ok) {
34 | 1 | 41µs | 61 | 6µs | s/^&// foreach @$ok; # spent 6µs making 61 calls to CORE::subst, avg 97ns/call
35 | 1 | 12µs |  |  | @{$cache}{@$ok} = (1) x @$ok;
36 |  |  |  |  | }
37 |  |  |  |  | }
38 |  |  |  |  |
39 |  |  |  |  | # spent 1.08ms (959µs+121µs) within Exporter::Heavy::heavy_export which was called 12 times, avg 90µs/call: # 12 times (959µs+121µs) by Exporter::Heavy::heavy_export_to_level or Exporter::import at line 22 of Exporter.pm, avg 90µs/call sub heavy_export {
40 |  |  |  |  |
41 |  |  |  |  | # Save the old __WARN__ handler in case it was defined
42 | 12 | 4µs |  |  | my $oldwarn = $SIG{__WARN__};
43 |  |  |  |  |
44 |  |  |  |  | # First make import warnings look like they're coming from the "use".
45 |  |  |  |  | local $SIG{__WARN__} = sub {
46 |  |  |  |  | # restore it back so proper stacking occurs
47 |  |  |  |  | local $SIG{__WARN__} = $oldwarn;
48 |  |  |  |  | my $text = shift;
49 |  |  |  |  | if ($text =~ s/ at \S*Exporter\S*.pm line \d+.*\n//) {
50 |  |  |  |  | require Carp;
51 |  |  |  |  | local $Carp::CarpLevel = 1; # ignore package calling us too.
52 |  |  |  |  | Carp::carp($text);
53 |  |  |  |  | }
54 |  |  |  |  | else {
55 |  |  |  |  | warn $text;
56 |  |  |  |  | }
57 | 12 | 33µs |  |  | };
58 |  |  |  |  | local $SIG{__DIE__} = sub {
59 |  |  |  |  | require Carp;
60 |  |  |  |  | local $Carp::CarpLevel = 1; # ignore package calling us too.
61 |  |  |  |  | Carp::croak("$_[0]Illegal null symbol in \@${1}::EXPORT")
62 |  |  |  |  | if $_[0] =~ /^Unable to create sub named "(.*?)::"/;
63 | 12 | 20µs |  |  | };
64 |  |  |  |  |
65 | 12 | 8µs |  |  | my($pkg, $callpkg, @imports) = @_;
66 | 12 | 2µs |  |  | my($type, $sym, $cache_is_current, $oops);
67 |  |  |  |  | my($exports, $export_cache) = (\@{"${pkg}::EXPORT"},
68 | 12 | 13µs |  |  | $Exporter::Cache{$pkg} ||= {});
69 |  |  |  |  |
70 | 12 | 3µs |  |  | if (@imports) {
71 | 12 | 3µs |  |  | if (!%$export_cache) {
72 | 1 | 900ns | 1 | 57µs | _rebuild_cache ($pkg, $exports, $export_cache); # spent 57µs making 1 call to Exporter::Heavy::_rebuild_cache
73 | 1 | 200ns |  |  | $cache_is_current = 1;
74 |  |  |  |  | }
75 |  |  |  |  |
76 | 12 | 41µs | 27 | 10µs | if (grep m{^[/!:]}, @imports) { # spent 10µs making 27 calls to CORE::match, avg 381ns/call
77 | 9 | 6µs |  |  | my $tagsref = \%{"${pkg}::EXPORT_TAGS"};
78 | 9 | 1µs |  |  | my $tagdata;
79 |  |  |  |  | my %imports;
80 |  |  |  |  | my($remove, $spec, @names, @allexports);
81 |  |  |  |  | # negated first item implies starting with default set:
82 | 9 | 11µs | 9 | 2µs | unshift @imports, ':DEFAULT' if $imports[0] =~ m/^!/; # spent 2µs making 9 calls to CORE::match, avg 233ns/call
83 | 9 | 3µs |  |  | foreach $spec (@imports){
84 | 23 | 20µs | 23 | 3µs | $remove = $spec =~ s/^!//; # spent 3µs making 23 calls to CORE::subst, avg 126ns/call
85 |  |  |  |  |
86 | 23 | 26µs | 23 | 9µs | if ($spec =~ s/^://){ # spent 9µs making 23 calls to CORE::subst, avg 374ns/call
87 | 23 | 40µs |  |  | if ($spec eq 'DEFAULT'){
88 |  |  |  |  | @names = @$exports;
89 |  |  |  |  | }
90 |  |  |  |  | elsif ($tagdata = $tagsref->{$spec}) {
91 |  |  |  |  | @names = @$tagdata;
92 |  |  |  |  | }
93 |  |  |  |  | else {
94 |  |  |  |  | warn qq["$spec" is not defined in %${pkg}::EXPORT_TAGS];
95 |  |  |  |  | ++$oops;
96 |  |  |  |  | next;
97 |  |  |  |  | }
98 |  |  |  |  | }
99 |  |  |  |  | elsif ($spec =~ m:^/(.*)/$:){
100 |  |  |  |  | my $patn = $1;
101 |  |  |  |  | @allexports = keys %$export_cache unless @allexports; # only do keys once
102 |  |  |  |  | @names = grep(/$patn/, @allexports); # not anchored by default
103 |  |  |  |  | }
104 |  |  |  |  | else {
105 |  |  |  |  | @names = ($spec); # is a normal symbol name
106 |  |  |  |  | }
107 |  |  |  |  |
108 | 23 | 2µs |  |  | warn "Import ".($remove ? "del":"add").": @names "
109 |  |  |  |  | if $Exporter::Verbose;
110 |  |  |  |  |
111 | 23 | 10µs |  |  | if ($remove) {
112 |  |  |  |  | foreach $sym (@names) { delete $imports{$sym} }
113 |  |  |  |  | }
114 |  |  |  |  | else {
115 | 23 | 59µs |  |  | @imports{@names} = (1) x @names;
116 |  |  |  |  | }
117 |  |  |  |  | }
118 | 9 | 34µs |  |  | @imports = keys %imports;
119 |  |  |  |  | }
120 |  |  |  |  |
121 | 12 | 2µs |  |  | my @carp;
122 | 12 | 3µs |  |  | foreach $sym (@imports) {
123 | 350 | 53µs |  |  | if (!$export_cache->{$sym}) {
124 |  |  |  |  | if ($sym =~ m/^\d/) {
125 |  |  |  |  | $pkg->VERSION($sym); # inherit from UNIVERSAL
126 |  |  |  |  | # If the version number was the only thing specified
127 |  |  |  |  | # then we should act as if nothing was specified:
128 |  |  |  |  | if (@imports == 1) {
129 |  |  |  |  | @imports = @$exports;
130 |  |  |  |  | last;
131 |  |  |  |  | }
132 |  |  |  |  | # We need a way to emulate 'use Foo ()' but still
133 |  |  |  |  | # allow an easy version check: "use Foo 1.23, ''";
134 |  |  |  |  | if (@imports == 2 and !$imports[1]) {
135 |  |  |  |  | @imports = ();
136 |  |  |  |  | last;
137 |  |  |  |  | }
138 |  |  |  |  | } elsif ($sym !~ s/^&// || !$export_cache->{$sym}) {
139 |  |  |  |  | # Last chance - see if they've updated EXPORT_OK since we
140 |  |  |  |  | # cached it.
141 |  |  |  |  |
142 |  |  |  |  | unless ($cache_is_current) {
143 |  |  |  |  | %$export_cache = ();
144 |  |  |  |  | _rebuild_cache ($pkg, $exports, $export_cache);
145 |  |  |  |  | $cache_is_current = 1;
146 |  |  |  |  | }
147 |  |  |  |  |
148 |  |  |  |  | if (!$export_cache->{$sym}) {
149 |  |  |  |  | # accumulate the non-exports
150 |  |  |  |  | push @carp,
151 |  |  |  |  | qq["$sym" is not exported by the $pkg module];
152 |  |  |  |  | $oops++;
153 |  |  |  |  | }
154 |  |  |  |  | }
155 |  |  |  |  | }
156 |  |  |  |  | }
157 | 12 | 3µs |  |  | if ($oops) {
158 |  |  |  |  | require Carp;
159 |  |  |  |  | Carp::croak(join("\n", @carp, "Can't continue after import errors"));
160 |  |  |  |  | }
161 |  |  |  |  | }
162 |  |  |  |  | else {
163 |  |  |  |  | @imports = @$exports;
164 |  |  |  |  | }
165 |  |  |  |  |
166 |  |  |  |  | my($fail, $fail_cache) = (\@{"${pkg}::EXPORT_FAIL"},
167 | 12 | 15µs |  |  | $Exporter::FailCache{$pkg} ||= {});
168 |  |  |  |  |
169 | 12 | 2µs |  |  | if (@$fail) {
170 |  |  |  |  | if (!%$fail_cache) {
171 |  |  |  |  | # Build cache of symbols. Optimise the lookup by adding
172 |  |  |  |  | # barewords twice... both with and without a leading &.
173 |  |  |  |  | # (Technique could be applied to $export_cache at cost of memory)
174 |  |  |  |  | my @expanded = map { /^\w/ ? ($_, '&'.$_) : $_ } @$fail;
175 |  |  |  |  | warn "${pkg}::EXPORT_FAIL cached: @expanded" if $Exporter::Verbose;
176 |  |  |  |  | @{$fail_cache}{@expanded} = (1) x @expanded;
177 |  |  |  |  | }
178 |  |  |  |  | my @failed;
179 |  |  |  |  | foreach $sym (@imports) { push(@failed, $sym) if $fail_cache->{$sym} }
180 |  |  |  |  | if (@failed) {
181 |  |  |  |  | @failed = $pkg->export_fail(@failed);
182 |  |  |  |  | foreach $sym (@failed) {
183 |  |  |  |  | require Carp;
184 |  |  |  |  | Carp::carp(qq["$sym" is not implemented by the $pkg module ],
185 |  |  |  |  | "on this architecture");
186 |  |  |  |  | }
187 |  |  |  |  | if (@failed) {
188 |  |  |  |  | require Carp;
189 |  |  |  |  | Carp::croak("Can't continue after import errors");
190 |  |  |  |  | }
191 |  |  |  |  | }
192 |  |  |  |  | }
193 |  |  |  |  |
194 | 12 | 2µs |  |  | warn "Importing into $callpkg from $pkg: ",
195 |  |  |  |  | join(", ",sort @imports) if $Exporter::Verbose;
196 |  |  |  |  |
197 | 12 | 88µs |  |  | foreach $sym (@imports) {
198 |  |  |  |  | # shortcut for the common case of no type character
199 | 350 | 523µs | 350 | 40µs | (*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next) # spent 40µs making 350 calls to CORE::subst, avg 115ns/call
200 |  |  |  |  | unless $sym =~ s/^(\W)//;
201 |  |  |  |  | $type = $1;
202 | 2 | 311µs | 2 | 36µs | # spent 21µs (6+15) within Exporter::Heavy::BEGIN@202 which was called: # once (6µs+15µs) by Exporter::as_heavy at line 202 no warnings 'once'; # spent 21µs making 1 call to Exporter::Heavy::BEGIN@202 # spent 15µs making 1 call to warnings::unimport
203 |  |  |  |  | *{"${callpkg}::$sym"} =
204 |  |  |  |  | $type eq '&' ? \&{"${pkg}::$sym"} :
205 |  |  |  |  | $type eq '$' ? \${"${pkg}::$sym"} :
206 |  |  |  |  | $type eq '@' ? \@{"${pkg}::$sym"} :
207 |  |  |  |  | $type eq '%' ? \%{"${pkg}::$sym"} :
208 |  |  |  |  | $type eq '*' ? *{"${pkg}::$sym"} :
209 |  |  |  |  | do { require Carp; Carp::croak("Can't export symbol: $type$sym") };
210 |  |  |  |  | }
211 |  |  |  |  | }
212 |  |  |  |  |
213 |  |  |  |  | sub heavy_export_to_level
214 |  |  |  |  | # spent 161µs (15+145) within Exporter::Heavy::heavy_export_to_level which was called 3 times, avg 54µs/call: # 3 times (15µs+145µs) by Time::HiRes::import at line 78 of Exporter.pm, avg 54µs/call {
215 | 3 | 700ns |  |  | my $pkg = shift;
216 | 3 | 400ns |  |  | my $level = shift;
217 | 3 | 1µs |  |  | (undef) = shift; # XXX redundant arg
218 | 3 | 900ns |  |  | my $callpkg = caller($level);
219 | 3 | 8µs | 3 | 16µs | $pkg->export($callpkg, @_); # spent 16µs making 3 calls to Exporter::export, avg 5µs/call
220 |  |  |  |  | }
221 |  |  |  |  |
222 |  |  |  |  | # Utility functions
223 |  |  |  |  |
224 |  |  |  |  | # spent 30µs within Exporter::Heavy::_push_tags which was called 2 times, avg 15µs/call: # once (21µs+0s) by Exporter::Heavy::heavy_export_ok_tags at line 250 # once (10µs+0s) by Exporter::Heavy::heavy_export_tags at line 246 sub _push_tags {
225 | 2 | 1µs |  |  | my($pkg, $var, $syms) = @_;
226 | 2 | 500ns |  |  | my @nontag = ();
227 | 2 | 2µs |  |  | my $export_tags = \%{"${pkg}::EXPORT_TAGS"};
228 |  |  |  |  | push(@{"${pkg}::$var"},
229 | 2 | 24µs |  |  | map { $export_tags->{$_} ? @{$export_tags->{$_}}
230 |  |  |  |  | : scalar(push(@nontag,$_),$_) }
231 |  |  |  |  | (@$syms) ? @$syms : keys %$export_tags);
232 | 2 | 4µs |  |  | if (@nontag and $^W) {
233 |  |  |  |  | # This may change to a die one day
234 |  |  |  |  | require Carp;
235 |  |  |  |  | Carp::carp(join(", ", @nontag)." are not tags of $pkg");
236 |  |  |  |  | }
237 |  |  |  |  | }
238 |  |  |  |  |
239 |  |  |  |  | sub heavy_require_version {
240 |  |  |  |  | my($self, $wanted) = @_;
241 |  |  |  |  | my $pkg = ref $self || $self;
242 |  |  |  |  | return ${pkg}->VERSION($wanted);
243 |  |  |  |  | }
244 |  |  |  |  |
245 |  |  |  |  | # spent 14µs (4+10) within Exporter::Heavy::heavy_export_tags which was called: # once (4µs+10µs) by Archive::Zip::BEGIN@11 at line 82 of Exporter.pm sub heavy_export_tags {
246 | 1 | 4µs | 1 | 10µs | _push_tags((caller)[0], "EXPORT", \@_); # spent 10µs making 1 call to Exporter::Heavy::_push_tags
247 |  |  |  |  | }
248 |  |  |  |  |
249 |  |  |  |  | # spent 24µs (4+21) within Exporter::Heavy::heavy_export_ok_tags which was called: # once (4µs+21µs) by Archive::Zip::BEGIN@37 at line 86 of Exporter.pm sub heavy_export_ok_tags {
250 | 1 | 4µs | 1 | 21µs | _push_tags((caller)[0], "EXPORT_OK", \@_); # spent 21µs making 1 call to Exporter::Heavy::_push_tags
251 |  |  |  |  | }
252 |  |  |  |  |
253 | 1 | 2µs |  |  | 1;