2005-12-11

When perl is not quite fast enough

来源: 本站收集整理 作者:佚名 评论 0 条
  。

Schwern notes that commenting out __END__ can cause surprises if the main body of your module is running under use strict; because now your AutoLoaded subroutines will suddenly find themselves being run under use strict. This is arguably a bug in the current AutoSplit - when it runs at install time to generate the files for AutoLoader to use it doesn't add lines such as use strict; or use warnings; to ensure that the split out subroutines are in the same environment as was current at the __END__ statement. This may be fixed in 5.10.

Elizabeth Mattijsen notes that there are different memory use versus memory shared issues when running under mod_perl, with different optimal solutions depending on whether your apache is forking or threaded.

=pod @ __END__
假如您用了一大块 pod 来描述你的代码,那么请尽量不要将其放在文件的上面部分。虽然 perl 分析器能很快的跳过 pod ,但是这不是魔法,它还是需要一点时间的。此外,它也需要从磁盘中读入 pod 就为了忽略它。
  #!perl -w

  use strict;
  =head1 You don't want to do that
  big block of pod
  =cut
  ...

  1;

  __END__
  =head1 You want to do this

假如您将您的代码放在 __END__ 后面,那么 perl 分析器就不会去注重它。这能省下一点点 CPU,但是假如你有一块很大的 pod (>4K) ,那它意味着文件的最后磁盘将不会被读进 RAM 。这也许能获得某些加速。[A helpful heckler observed that modern raid systems may well be reading in 64K chunks, and modern OSes are getting good at read ahead, so not reading a block as a result of =pod @ __END__ may actually be quite rare.]

假如你还是将您的 pod (和测试)放在函数代码的旁边(这看起来更是一种好习惯),那么此建议与您无关。

无关的倒入会变慢

Exporter 是用 perl 所写的。虽然它很快,但也不是即时的。

许多模块,为了节省您的输入,都默认在您的命名空间内倒出许多函数和符号变量。假如您只有一个参数在 use 后(模块名参数),比如

    use POSIX;          # Exports all the defaults

于是 POSIX 将有用地在您的命名空间内倒出它的默认符号变量列表。假如您在模块名后有一列表,那它只倒出此列表的符号变量。假如列表为空, 不到处任何符号变量:

    use POSIX ();       # Exports nothing.

您仍然可以使用所有的函数和其他符号变量 - 但您必须使用它们的全名,如在前面输入 POSIX:: 。许多人说这样实际上让您的代码更干净,而且现在很清楚的知道子程序是在哪定义的。除了这些,它还更快:
共13页: 上一页 [1] [2] [3] [4] 5 [6] [7] [8] [9] [10] [11] [12] [13] 下一页

(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:被百度降权后,网站该怎么办?  
下一篇:SQL Server2000数据库文件损坏时如何恢复
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号