I occasionally do some code development for a customer who has a HUGE site (I'd estimate in excess of 500,000 lines of code). I keep running into some really poor coding practices by previous developers. Of course, I get paid for fixing them, so I guess that's good.
One that really drives me up the wall is that there are lots of array references without quote marks on the element names. Because I occasionally have to refer to the error logs to find my coding errors (yes, every once in a while, I make them too), I noticed that the logs filled up fast with messages about the missing quotes and creating new variables. I knew this had to be slowing down the execution.
So I set up a little benchmark on one of my local test sites.
<?php
$array = array('apple' => 1, 'banana' => 2, 'carrot' => 3, 'date' => 4, 'eggplant' => 5);
$how_many = 10000;
$start = microtime(TRUE);
for ($i = 1; $i <= $how_many; $i++) {
$a = $array['apple'];
$b = $array['banana'];
$c = $array['carrot'];
$d = $array['date'];
$e = $array['eggplant'];
}
$end = microtime(TRUE);
$with = $end - $start;
echo '<p>With quotes took '. number_format($with * 1000000, 2) ." microseconds.</p>";
$start = microtime(TRUE);
for ($i = 1; $i <= $how_many; $i++) {
$a = $array[apple];
$b = $array[banana];
$c = $array[carrot];
$d = $array[date];
$e = $array[eggplant];
}
$end = microtime(TRUE);
$without = $end - $start;
echo '<p>Without quotes took '. number_format($without * 1000000, 2) ." microseconds.</p>";
echo '<p>That\'s '. number_format($without / $with, 1) ." times as long!</p>";
?>
If my benchmark is flawed, I'd love for you to tell me.
Here's the result:
With quotes took 11,510.85 microseconds.
Without quotes took 390,300.99 microseconds.
That's 33.9 times as long!
Comments
Nice work!
Nice work!
I've been tracing through Drupal with a debugger a lot lately and I've noticed there are quite a number of places in core Drupal includes and modules where the error handler is called for uninitialized variables etc. Based on your benchmarks these uninitialized variables could be having a sizable effect on performance.
How hard is it to get patches for these kind of things included in Drupal core?
Right now
Right now is a great time to report them, especially if they still exist in D6. There is little chance of them being fixed in D5 unless they represent a security exposure. But D6 is getting ready to roll out the door, so the developers would really like to have a long list of problems that were fixed.
One thing that I found rather interesting is that on the site I find these problems on, the errors are flooding the error log, but on my test site, they aren't coming out. But obviously, there is a definite impact on performance.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru
Coder check
I've submitted a feature request to the Coder module to check this, but he's asking for additional input.
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru