Matthew Weier O'Phinney wrote:
In this particular case, the performance enhancements were made to the
PluginLoader, which is used in a variety of places in the framework.
Basically, we were looping over paths manually and checking if a file
was readable; this becomes slower and slower the more paths that need to
be traversed to find the correct file. Ironically, there's an option in
loadFile() that allows you to pass a set of directories to loop over;
directory iteration is done by resetting the include_path briefly and
using fopen(), which has an argument for searching the include_path --
which is many times faster than manually doing it. The net gain is
around 12.5% in a real-world application (i.e., 1/8 increase), but could
vary based on the requirements of your application.
Just as a minor followup to this. I see that array_key_exists() is used
quite frequently in the Zend codebase.
After some simple benchmarks, I note that this can often be improved by
the simple use of an isset() or !empty() call instead (these being
language constructs rather than function calls).
Ex1: array_key_exists('foo', $arr) == isset($arr['foo'])
Ex2: (array_key_exists('foo', $arr) && true == $arr['foo']) ==
!empty($arr['foo'])
This does not always hold 100% true and it is sometimes necessary to use
array_key_exists where isset() or empty() would give incorrect results
in the context, e.g.
$arr['foo'] = null;
isset($arr['foo']) == false
!empty($arr['foo']) == false
array_key_exists('foo', $arr) == true
Having done some basic benchmarks, on this thread:
http://thread.gmane.org/gmane.comp.php.general/190070
the second example above gave me a ~3.5x speed increase. If there is a
2-depth array that needs checking then it yielded a ~4.5x speed increase.
This would seem like a fairly easy "low hanging fruit" optimisation that
could be made in the ZF with minimum of hassle.
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]