dublish.com— Here is a list of a few very simple tips for optimizing your php/mysql applications. Keep these in mind while developing to survive the digg-effect.
May 4, 2006View in Crawl 4
"Most of these are either wishful thinking or give speed improvement that is too small to reliably measure."Indeed. While some of these may save you a few nanoseconds here and there, there's a good chance that an unnecessary nested loop, or unindexed query is taking thousands of times longer than it should.Find the _real_ trouble spots in your application, and fix _them_. Which style of quotes you use isn't going to make a noticable difference in ANY application. Period.(Also, the article mentions using , (comma) as a concatenation operator instead of . (period) -- that's pure bulls**t. Period is the only available concatination operator in PHP -- as mentioned on the comments on the site itself.)
Here's what you need to know about optimization (I forget what the law is called). If you optimize code that accounts for 1% of your processing time by 100% you still only get 0.5% improvement. And mind you, 100% is a huge improvement to a chunk of code that is reasonably well-written. It doesn't matter how many trillions of hits you get, 0.5% is 0.5%. So before you do any optimization, profile your code and see where you're spending 10%, 20% or 50% of your time. Things like parsing and concatenating strings probably accounts for less than 0.01% of processing time in any application that has a purpose beyond simple text manipulations. So, no, every little bit does not count. At least not in any meaningful way.
A 0.5% increase can lead to a significant server response - especially if you understand gamma processes and load averages. If your box is currently running at 99.9% then then the extra 0.5% means your box is running at 100.1% ie more than it can do - and so all the .1% add up and mean all requests end up delayed!!!
Actually, echo is very special in this behavior. You can put echo "hello"," world"; and the output will be exactly what is expected from an string concatenation (try it). echo is like a function that takes a variable number of arguments, but without parenthesis
Two little tips more, worth adding to the list:1. use preg_* instead of reg_* functions. They're always faster.2. use ctype_digit, ctype_alpha, etc.. instead of is_int, is_numeric.. ctype_* functions are twice as fast.
Thanks, kerplunk, I'll have to test that out and see how it compares. I started using Zen's optimizer when they released a free version and it did the trick for me, so I just didn't dig much deeper; )
danorakMay 4, 2006
I would have thought that the fastest way to speed up your PHP is to throw it away and use ASP.NET instead.....
deputaatsMay 4, 2006
He's saying: "Use NULL as default value as much as you can, it speeds up execution and saves one bit."In MySQL doc: "Declare columns to be NOT NULL if possible. It makes everything faster and you save one bit per column. If you really need NULL in your application, you should definitely use it. Just avoid having it on all columns by default." --> <a class="user" href="http://dev.mysql.com/doc/refman/5.0/en/data-size.html">http://dev.mysql.com/doc/refman/5.0/en/data-size.html</a>
merrebornMay 4, 2006
"Most of these are either wishful thinking or give speed improvement that is too small to reliably measure."Indeed. While some of these may save you a few nanoseconds here and there, there's a good chance that an unnecessary nested loop, or unindexed query is taking thousands of times longer than it should.Find the _real_ trouble spots in your application, and fix _them_. Which style of quotes you use isn't going to make a noticable difference in ANY application. Period.(Also, the article mentions using , (comma) as a concatenation operator instead of . (period) -- that's pure bulls**t. Period is the only available concatination operator in PHP -- as mentioned on the comments on the site itself.)
dasil003May 4, 2006
Here's what you need to know about optimization (I forget what the law is called). If you optimize code that accounts for 1% of your processing time by 100% you still only get 0.5% improvement. And mind you, 100% is a huge improvement to a chunk of code that is reasonably well-written. It doesn't matter how many trillions of hits you get, 0.5% is 0.5%. So before you do any optimization, profile your code and see where you're spending 10%, 20% or 50% of your time. Things like parsing and concatenating strings probably accounts for less than 0.01% of processing time in any application that has a purpose beyond simple text manipulations. So, no, every little bit does not count. At least not in any meaningful way.
drbaggyMay 4, 2006
A 0.5% increase can lead to a significant server response - especially if you understand gamma processes and load averages. If your box is currently running at 99.9% then then the extra 0.5% means your box is running at 100.1% ie more than it can do - and so all the .1% add up and mean all requests end up delayed!!!
sideralMay 5, 2006
Actually, echo is very special in this behavior. You can put echo "hello"," world"; and the output will be exactly what is expected from an string concatenation (try it). echo is like a function that takes a variable number of arguments, but without parenthesis
sideralMay 5, 2006
Two little tips more, worth adding to the list:1. use preg_* instead of reg_* functions. They're always faster.2. use ctype_digit, ctype_alpha, etc.. instead of is_int, is_numeric.. ctype_* functions are twice as fast.
creepingdeathMay 5, 2006
Thanks, kerplunk, I'll have to test that out and see how it compares. I started using Zen's optimizer when they released a free version and it did the trick for me, so I just didn't dig much deeper; )
kevmasterAug 2, 2007
How I managed to easily survive 2 frontpage diggs at the same time. An in depth article.<a class="user" href="http://digg.com/linux_unix/How_to_easily_survive_the_Digg_effect">http://digg.com/linux_unix/How_to_easily_survive_the_Digg_effect</a>
visbitsApr 30, 2010
Be sure you learn about how indexes work, and look at this example of what not to do.<a class="user" href="http://sudomakeinstall.com/mysql/2010/04/27/mysql-query-hint-of-the-day/" rel="nofollow">http://sudomakeinstall.com/mysql/2010/04/27/mysql- ...</a>