Re: minute performance gain
| From: | Greg Beaver | Date: | Mon, 18 Oct 2004 17:16:15 +0000 |
| Subject: | Re: minute performance gain | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-33941@lists.php.net to get a copy of this message | ||
Jon Parise wrote:
On Sun, Oct 17, 2004 at 02:05:15PM -0400, Greg Beaver wrote:Yes, but the majority of classes that extend PEAR don't have a destructor. Notable exceptions to this rule are Archive_Tar and PEAR_Common, and I guess MDB :). DB_common, for instance, does not define a destructor, and neither does PEAR_Error - the two most commonly used classes that extend PEAR. Also note that PEAR_Error does not call PEAR::PEAR(), so the destructor check is never performed. Also, even though PEAR defines _PEAR, note the code in PEAR::PEAR():I took the register_shutdown_function and moved it to the PEAR class constructor, inside the code that checks for destructors, and found a miniscule performance gain. Zend IDE's profiler reported that the time it takes to run 'PEAR.php'; decreased from .35 ms to .28 ms. By far the most significant performance hit comes from the require_once call, which leads me to believe that even using PEAR_Exception would do nothing to improve performance unless you put everything in 1 big-ass file. :)To be fair, you only see this performance gain when no destructor is exists (and register_shutdown_function() is not called), yes?
while ($classname && strcasecmp($classname, "pear")) {
$destructor = "_$classname";
if (method_exists($this, $destructor)) {
global $_PEAR_destructor_object_list;
$_PEAR_destructor_object_list[] = &$this;
static $registered = false;
if (!$registered) {
register_shutdown_function("_PEAR_call_destructors");
$registered = true;
}
break;
} else {
$classname = get_parent_class($classname);
}
}
In English, this code will cycle through the parent classes until it finds a destructor or the class is PEAR - the _PEAR destructor is never registered.
Greg