autoload在使用最新版本的APC时是否会影响性能?有相关基准测试吗?

19

我正在尝试找到一个明确的答案,回答autoload在使用APC时为什么会降低性能(基准测试?)

P.S. 使用Google / StackOverflow找到了这个链接,但我想知道这是否仍然适用? PHP必须已经改进以处理此问题吧?因为autoload很酷!


1
参考:https://dev59.com/IHM_5IYBdhLWcg3wZSM6、https://dev59.com/oXI-5IYBdhLWcg3wQWCc。 - Mike B
谢谢Mike B. 我看了那个主题。我希望能有一些基准测试数据。我想我应该更新我的答案。 - Alfred
2
有趣的问题 - 我甚至从未想过自动加载会引起问题,而我使用了一个使用大量自动加载并从APC中受益匪浅的库,因此我的想法是简单的自动加载对APC并不坏。不过进行基准测试会很有趣。 - Hamish
2个回答

6
个人认为依赖 __autoload() 不是一个好的实践。PHP 是一种弱类型语言,而不是惰性类型语言。 :)
以下是一些性能测试: Rasmus 对此的回答(您也找到了)是我多年来的指导原则:
<arnaud_> does autoload have a performance impact when using apc ?
<Rasmus_> it is slow both with and without apc
<Rasmus_> but yes, moreso with apc because anything that is autoloaded is pushed down into the executor
<Rasmus_> so nothing can be cached
<Rasmus_> the script itself is cached of course, but no functions or classes
<Rasmus_> Well, there is no way around that
<Rasmus_> autoload is runtime dependent
<Rasmus_> we have no idea if any autoloaded class should be loaded until the script is executed
<Rasmus_> top-level clean deps would speed things up a lot
<Rasmus_> it's not just autoload
<Rasmus_> it is any sort of class or function declaration that depends on some runtime context
<Rasmus_> if(cond) function foo...
<Rasmus_> if(cond) include file
<Rasmus_> where file has functions and classes 
<Rasmus_> or heaven forbid: function foo() { class bar { } }

1
它仍然适用于PHP5.3吗?我想看到一些支持这个说法的基准测试或文章之类的东西! - Alfred
这是我能找到的迄今为止最全面的基准测试 - http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html - seven

5

我进行了更多的搜索,并发现了这篇有趣的文章,以下是摘要:

每种策略都运行了10次基准测试:

enter image description here

结论

每种方法都有其优点。在开发过程中,您不希望必须运行脚本来生成类映射或手动更新类映射以添加新类。尽管如此,如果您预计网站将有大量流量,则可以在部署期间轻松运行脚本为您构建类映射,从而让您从应用程序中获得一些额外的性能。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接