Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-8393

Performance improvement in DataObject->fetch()

    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->debug("$kk = ". $array[$k], "fetchrow LINE", 3); }

      $this->$kk = $array[$k];
      }

      The new code is:
      $keys = str_replace(array("."," "), "_", array_keys($array));
      $i = 0;
      foreach ($array as $val)

      { $key = $keys[$i++]; if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) $this->debug("$key = $val", "fetchrow LINE", 3); $this->$key = $val; }

      We are using this modification, and are seeing performance improvements on all platforms.

        Attachments

          Activity

            People

            • Assignee:
              deepak Deepak Srivastava
              Reporter:
              zalewski Ken Zalewski
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: