Do Not Micro-Optimize
Whenever I read blog postings such as that one (in the spirit of John McCain's that one reference to Barack Obama) I get a little bit angry.
"calling a static method is faster than an object method"
It is called Object-Oriented Programming. Not "Class-Oriented Programming". Nor "Procedural Progamming with Classes as Namespaces".
The small performance gain you may or may not get at deployment-time by using static method calls instead of using instance method calls comes at the price of problems at development-time.
One of the problems at development-time that you are digging yourself into is that of untestable code: static methods are death to testability. Use them when it makes sense to use them and not because you think you can improve the performance of your website by using them.
I bet that your problems lie elsewhere when you think that you can solve them by a micro-optimization such as this. Have a look at Ilia's Common Optimization Mistakes slides for more information on this topic.
10/03/2009 at 14:57 Permalink
I think the key point to consider here is that these days hardware and performance is getting cheaper and cheaper. Fixing code problems is getting more and more expensive.
Sacrificing good coding practice for barely noticeable performance gains seems like lunacy to me.
Reply
10/03/2009 at 16:26 Permalink
Reply
10/03/2009 at 17:34 Permalink
Reply
13/03/2009 at 15:27 Permalink
I hear so much, "It's from Zend, so it must be good...", etc but has any serious PHP developer actually taken a good look under the hood recently?!
Christ, I hope I ain't gonna be around when the sh*t hits the fan on this one :eek:
Reply
23/10/2009 at 16:09 Permalink
I do not disagree with the article as you so plainly do. I find that those articles are great for getting beginners to code properly from the start to ensure cleaner, better, and hopefully faster code. As a duct-tape programmer, I have spent much of my time working on platforms of other programmers. I don’t want to get into detail but if a few of the concepts in the provided article were used the system would have ran much smoother. The system I’m using as an example is about 1.4GB in size. I can admit that the majority of the issues in the platform are that there is zero documentation (Fun for me, and that’s sarcasm), horrible SQL queries, and poorly written code. I do agree that SQL queries contribute to the penalty of speed; I want to argue that these concepts are not entirely bad. They are still good standards to be followed by any beginner. By going through the entire system and changing double quotes to single quotes, has noticeably improved performance. For most projects I would agree with you, but for larger projects, I kindly disagree.
Replacing hardware is a nice solution, and in many cases it is enough. While this may be the cheaper and faster solution, this is not the best. Replacing hardware works, but it doesn’t fix the bigger issue, which can be fixed by cleaning and optimizing the code.
Micro-optimize is not a bad thing, its just good logic to follow for beginners. The experts will learn/know when to use it or not.
This is my look on this as someone who has once been a self-taught beginner. Almost ten years of PHP now has taught me this. While I am working on my ZCE currently, I do want to say I am not a fan of Zends’ current framework, and I agree with Les about the quality of the framework. Asides from my areas of disagreement, nice post.
Reply