Details
-
Type:
Patch
-
Status: Done/Fixed
-
Priority:
Major
-
Resolution: Fixed/Completed
-
Affects Version/s: 3.3.6
-
Fix Version/s: 3.4.5
-
Component/s: Core CiviCRM
-
Labels:None
Description
The fetch() method in DataObject calls str_replace() in a loop, in order to modify the keys of the array. This is an expensive operation, especially since fetch() is called in a loop itself when fetching records one row at a time.
The str_replace() function can perform its own iteration on arrays, so we can cut down drastically on the number of calls to str_replace() by re-writing the keys prior to entering the loop.
The code block starts on line 560.
The original code is:
foreach($array as $k=>$v) {
$kk = str_replace(array("."," "), "_", $k);
if (!empty($_DB_DATAOBJECT['CONFIG']['debug']))
$this->$kk = $array[$k];
}
The new code is:
$keys = str_replace(array("."," "), "_", array_keys($array));
$i = 0;
foreach ($array as $val)
We are using this modification, and are seeing performance improvements on all platforms.