2009-02-19 17:50
浏览 81


I was working on my website written in php/mysql. When I first wrote it, it was spaghetti with lots of php embedded in html and the like - very hard to maintain.

I rewrote the whole thing with a nice modular structure with OOPS, and now it is much easier to maintain and expand.

But when testing the site performance using webwait and siege, the newer, better structured version seems to run and load slower than the spaghetti code version.

There's a difference of nearly 1 second in loading time - 2.39s vs 3.81s

Nothing else was changed except the php code - not the js, not the css

So what is the problem here? Should I revert back to the old code? Has this happened to others?


  • I have done some analysis using cachegrind, inclued and I think the code is pretty good.
  • I also know that the problem is not entirely OOPS but the greater structure etc. and also that OOP doesn't at all guarantee better performance.
  • I have run the code multiple times too.
  • I've used cachegrind with kcachegrind, inclued, siege (most of the tools Rasmus lerdorf outlined in his drupalcon 2008 talk on 'Simple is Hard')

What I want to know is how others deal with this.

图片转代码服务由CSDN问答提供 功能建议

我正在使用php / mysql编写的网站上工作。 当我第一次写它的时候,是hag等嵌入了大量php的意大利面 - 非常难以维护。

我用OOPS重写了一个很好的模块化结构,并且 现在它更容易维护和扩展。

但是在使用 webwait测试网站性能时 和围攻,较新的,结构更好的版本似乎比意大利面条代码版本运行和加载速度慢。

加载时间差异接近1秒 - 2.39秒vs 3.81s

除了PHP代码之外没有其他任何改变 - 不是js,而不是css

那么这里有什么问题? 我应该恢复旧代码吗? 这是否发生在其他人身上?


  • 我使用 cachegrind进行了一些分析,包括我认为\ ncode非常好。
  • 我也知道问题并不完全是 OOPS而是更大的结构等 而且OOP根本没有 保证更好的性能。
  • 我也多次运行代码。
  • 我使用了cachegrind和 kcachegrind,包括,siege(大多数 这些工具Rasmus lerdorf在2008年的drupalcon上谈到了' 简单 很难'

    我想知道的是别人如何处理这个问题。 < / p>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • dragonlew9876 2009-02-25 15:41

    I can think of a couple of points to consider:

    • It's not a choice of OOP vs spaghetti code. There are other paradigms that may be just as maintainable and structured as OOP, but with different performance characteristics. It is possible to write OOP code using only simple procedural language features (many big C frameworks use a very OOP-ey style.) A more functional style may also be simpler in some cases. OOP isn't the One True Paradigm.
    • There are different degrees of OOP. Modelling data as objects does not in most languages cause a noticeable performance difference (I don't know how PHP performs in this area, though, but with PHP I always expect the worst). However, virtual functions, inheritance (and especially multiple inheritance) are slower and add overhead that often could have been avoided. Which OOP features do you use? Is there a simpler OOP design that would do the job, but with less reliance on "slow" language features?

    On top of that, the usual obviously applies (can you optimize the algorithm, enable caching or precompilation, and so on - but while those may help dramatically, they're not specific to OOP)

    解决 无用
    打赏 举报
  • 查看更多回答(6条)

相关推荐 更多相似问题