使用APC(最新版本/最新版本)时,autoload是否真的会破坏性能.基准?

Alf*_*red 19 php apc

我试图找到一个明确的答案,自动加载在使用APC时杀死性能的问题及其原因(基准测试?)

PS 使用谷歌/ stackoverflow 发现此链接,但我想知道这是否仍然存在?必须改进PHP来处理这个问题?因为自动加载很酷!

sev*_*ven 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 { } }
Run Code Online (Sandbox Code Playgroud)


Alf*_*red 5

我做了一些谷歌搜索,发现这篇有趣的文章总结如下:

基准测试每个策略运行10次:

在此输入图像描述

结论

每种方法都有其优点.在开发期间,您不希望每次添加新类时都必须运行脚本来生成类映射或手动更新类映射.也就是说,如果您希望您的站点有大量流量,那么在部署期间运行脚本以便为您构建类映射非常容易,因此可以让您从应用程序中获得一些额外的性能.