如果代码中没有诊断,为什么Perl要编译diagnostics.pm?
当我查看v4的输出时,我在报告源代码文件中发现了如果代码中没有诊断,为什么Perl要编译diagnostics.pm?,perl,devel-nytprof,Perl,Devel Nytprof,当我查看v4的输出时,我在报告源代码文件中发现了diagnostics.pm——按排他时间排序,然后按名称排序 首先,我不明白为什么会出现在生产代码中。我对报告进行了深入研究,发现它是由main::BEGIN@17。这又是以下几行: # spent 34µs (26+8) within main::BEGIN@15 which was called: # once (26µs+8µs) by main::RUNTIME at line 15 use strict; # spent 34µs m
diagnostics.pm
——按排他时间排序,然后按名称排序
首先,我不明白为什么会出现在生产代码中。我对报告进行了深入研究,发现它是由main::BEGIN@17
。这又是以下几行:
# spent 34µs (26+8) within main::BEGIN@15 which was called: # once (26µs+8µs) by main::RUNTIME at line 15
use strict;
# spent 34µs making 1 call to main::BEGIN@15 # spent 8µs making 1 call to strict::import
# spent 36µs (17+19) within main::BEGIN@16 which was called: # once (17µs+19µs) by main::RUNTIME at line 16
use warnings;
# spent 36µs making 1 call to main::BEGIN@16 # spent 19µs making 1 call to warnings::import
# spent 292ms (171+121) within main::BEGIN@17 which was called: # once (171ms+121ms) by main::RUNTIME at line 17
no diagnostics;
# spent 292ms making 1 call to main::BEGIN@17
# spent 135µs (27+108) within main::BEGIN@18 which was called: # once (27µs+108µs) by main::RUNTIME at line 18
use Carp qw( carp croak );
所以这似乎是罪魁祸首。我删除了no diagnostics
行,电话就没了,有效地节省了大约300毫秒的时间
下面是关于no
关键字的说明:
有一个相应的no声明,表示不支持含义
通过use导入,即调用unport模块列表而不是
进口。它的行为与导入对版本、省略或
空列表,或找不到不重要的方法
no integer;
no strict 'refs';
no warnings;
因此,这里是我的实际问题:如果我调用无诊断
,它在不受影响
之前实际加载,我的假设正确吗?
对no diagnostics
的调用是否与此代码类似
BEGIN {
require diagnostics.pm;
diagnostics->unimport;
}
因此,仅仅是不重要的东西,从来没有被导入,是不是一个坏主意,因为它实际上是先加载的
如果我调用无诊断
,它在未被导入之前就被加载了,这一假设是否正确
对。它确实完全等同于
BEGIN {
require diagnostics;
diagnostics->unimport;
}
因此,
没有模块
命令实际加载和编译模块;包括执行不在任何子中、开始块中的代码等;对于给定模块的所有依赖项也是一样的(对于每个使用/内部要求)。在有人指出之前:我并没有试图优化任何东西,我只是试图理解调用的内容。在“普通”情况下,模块已经加载,因为您在某个地方使用了它,因此,require
是不可操作的,只有不重要的
才重要。但是是的,假设模块在任何之前的点上都没有被require
d,那么no
将这样做。