dongyong8098 2009-11-27 14:45
浏览 32

“清洁代码”对性能的影响

At my workplace we're planning a major refactor on our core product, a web application with several 'modules'. I quoted that because that's one of our main concerns: modules are not really modules, the whole thing is monolithic. The application is written in PHP with smarty templating and using Pear for accessing a MySQL database. We're not really concerned with database independence, although it would be nice if that wouldn't take months to implement.

Our main concerns are that development time/cost is increasing exponentially because of bugs popping up in unrelated places and not having a sound common architecture to rely on to get the most common functionality (each module is basically copy/paste from the previous one, then adapt).

I've got some experience with the web MVC principle, mainly in ASP.NET MVC. I like the clean separation it offers and the testability. However, when trying this on a local machine the app is simply a lot slower than it should be.

Alright, enough introduction, off to the questions: - Should I rely on caching modules? Does this remove most of the overhead using a good architecture provide? Something like APC.

  • The application is mainly read. Writing is mainly single values (change a single field on a record). Any OR/M for PHP that are good at this?
  • Also looking for a flexible MVC framework. I know Zend, CakePHP, maybe Symfony?

The tricky part is that we don't have the luxury of being able to do a full rewrite. We'll have to incrementally improve a currently very messy codebase. This has to be done while writing new code, or fixing bugs. One thing I'd really, REALLY like to be able to do is write a regression test for a new bug before fixing it, to prevent it from popping up again later (this happens, occasionally).

The stack I'm currently considering contains:

  • MVC framework of choice
  • Logging (log4php?)
  • an OR/M of choice (doesn't have to be dynamic, code generation is fine too)
  • IoC container of choice
  • Smarty Templating, perhaps abstracted so we can switch it out if we need to.
  • Opcode cache of choice (we're using one now, forgot which one, have to ask sysadmin)

The main point that worries me is the performance implications of creating clean code in PHP. Seeing it's a parsed language opposed to something like the .NET/Java web stack, creating abstractions for otherwise in-line code (with obligatory separation in different files) might create new problems on another level.


Note: Retag if you come up with more appropriate tags, I'm not sure on the current ones.

  • 写回答

5条回答 默认 最新

  • dreamwind1985 2009-11-27 14:59
    关注

    Having a clean setup isn't a performance issue, usually. Most performance is spent with databases or other external systems you're talking to.

    Except for these there are usually one or two hotspots which might be worth optimizing but for that you should start with a clean design, then use a profiler (like XDebug or ZendDebugger) to identify the bottlenecks.

    A clean software design is way more important than the 0.01% performance gain by a "optimized" design. Usuallyit's even cheaper to buy and run more hardware than worry about an "optimized" codebase which is unmaintainable.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么