Als ich auf die Ausgabe von Devel::NYTProf v4 für eine CGI program sah, stieß ich auf die diagnostics.pm
im Bericht Quellcode-Dateien - nach exclusiver Zeit sortiert dann Name.Warum kompiliert Perl diagnostics.pm, wenn ich keine Diagnose in meinem Code habe?
Zuerst habe ich nicht verstanden, warum das in der Produktion Code wäre. Ich vertiefte mich tiefer in den Bericht und fand heraus, dass es von main::[email protected]
aufgerufen wurde. Das ist wiederum folgende Zeile:
# spent 34µs (26+8) within main::[email protected] which was called: # once (26µs+8µs) by main::RUNTIME at line 15
use strict;
# spent 34µs making 1 call to main::[email protected] # spent 8µs making 1 call to strict::import
# spent 36µs (17+19) within main::[email protected] which was called: # once (17µs+19µs) by main::RUNTIME at line 16
use warnings;
# spent 36µs making 1 call to main::[email protected] # spent 19µs making 1 call to warnings::import
# spent 292ms (171+121) within main::[email protected] which was called: # once (171ms+121ms) by main::RUNTIME at line 17
no diagnostics;
# spent 292ms making 1 call to main::[email protected]
# spent 135µs (27+108) within main::[email protected] which was called: # once (27µs+108µs) by main::RUNTIME at line 18
use Carp qw(carp croak);
Das scheint also der Schuldige zu sein. Ich entfernte die no diagnostics
Linie, und der Anruf war weg, effektiv ungefähr 300ms Zeit speicherend.
Hier ist, was perldoc use
sagt über das no
Stichwort:
Es gibt eine keine Erklärung entspricht, die durch die Verwendung importierter Bedeutungen unimports, das heißt, es unimport Modulliste statt Import nennt. Es verhält sich genauso wie Import mit VERSION, einer weggelassenen oder leeren LIST, oder es wird keine unimport-Methode gefunden.
no integer; no strict 'refs'; no warnings;
Also hier ist meine eigentliche Frage: Bin ich in der Annahme korrigieren, wenn ich no diagnostics
aufrufen, wird es tatsächlich geladen, bevor es unimport
ed ist?
Ist der Anruf an no diagnostics
diesem Code ähnlich?
BEGIN {
require diagnostics.pm;
diagnostics->unimport;
}
Folglich ist es eine schlechte Idee, nur unimport Sachen, die importiert wurde nie, denn das ist es eigentlich zuerst lädt?
Bevor irgendjemand darauf hinweist: Ich versuche (noch) nichts zu optimieren, ich versuche nur zu verstehen, was überhaupt aufgerufen wird. – simbabque