使用 APC(最新版本/最新)时,自动加载真的会降低性能吗?基准?

发布于 2024-10-13 19:16:18 字数 196 浏览 5 评论 0原文

我试图为使用 APC 时自动加载会降低性能的问题找到明确的答案,为什么(基准?)

PS 发现了这个 链接使用google/stackoverflow,但我想知道这是否仍然成立? PHP 必须改进才能处理这个问题吗?因为自动加载有点酷!

I am trying to find a definite answer to the question that autoload kills performance when using APC and why(benchmarks?)

P.S. Found this link using google/stackoverflow, but I am wondering if this still holds? PHP must been improved to handle this? Because autoload is kind of cool!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

要走就滚别墨迹 2024-10-20 19:16:18

就我个人而言,我不认为依赖 __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 { } }

Personally, I don't believe relying on __autoload() is good practice. PHP is a loosely typed language, not a lazily typed language. :)

Check out some performance here:

Rasmus's answer on this (which you also found) was my guidline through all this years:

<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 { } }
祁梦 2024-10-20 19:16:18

我又进行了一些谷歌搜索,发现了这个有趣的文章总结如下:

每个策略运行了 10 次基准:

在此处输入图像描述

结论

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

I did some more googling and found this interesting article summarized below:

Benchmarks were run 10 times for each strategy:

enter image description here

Conclusion

Each approach has its merits. During development, you don't want to necessarily run a script to generate the class map or manually update the class map every time you add a new class. That said, if you expect a lot of traffic to your site, it's trivially easy to run a script during deployment to build the class map for you, and thus let you eke out a little extra performance from your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文