鉴于这两个仅更改Module::FOO()
和的评估FOO()
。
# Symbols imported, and used locally.
eval qq[
package Foo$num;
Module->import();
my \$result = Module::FOO() * Module::FOO();
] or die $@;
# Symbols imported, not used locally referencing parent symbol.
eval qq[
package Foo$num;
Module->import();
my \$result = FOO() * FOO();
] or die $@;
为什么顶部块占用的空间要少得多?脚本和输出复制如下,
脚本
package Module {
use v5.30;
use warnings;
use constant FOO => 42;
use Exporter 'import';
our @EXPORT = ('FOO');
}
package main {
use v5.30;
use autodie;
use warnings;
$|=1;
say "Our PID is $$";
for my $num ( 0..1e5 ) {
eval qq[
package Foo$num;
Module->import();
my \$result = Module::FOO() * Module::FOO();
] or die $@;
eval qq[
package Foo$num;
Module->import();
my \$result = FOO() * FOO();
] or die $@;
}
say "DONE";
_debug();
}
sub _debug {
open my $fh, "<", "/proc/$$/status";
while ( <$fh> ) {
next unless /Rss/;
print;
}
}
结果
包(命名空间)合格
RssAnon: 78896 kB
RssFile: 5220 kB
RssShmem: 0 kB
本地进口
RssAnon: 168180 kB
RssFile: 5496 kB
RssShmem: 0 kB