duanlei20082008 2009-02-19 17:50
浏览 82
已采纳

OOPS,表现如何?

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?

Edit:

  • 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.

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作