Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-36761

Unnecessary calls to "count()" can be optimized to improve performance

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.6, 2.3.3, 2.4
    • Fix Version/s: 2.2.7, 2.3.4, 2.4.1
    • Component/s: Gradebook
    • Labels:
    • Testing Instructions:
      Hide

      This code is pretty conclusively covered by the unit tests (phpunit grade_category_testcase lib/grade/tests/grade_category_test.php)

      Show
      This code is pretty conclusively covered by the unit tests (phpunit grade_category_testcase lib/grade/tests/grade_category_test.php)
    • Affected Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE, MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull Master Branch:
      MDL-36761_loop

      Description

      In the function "apply_limit_rules()" in "/lib/grade/grade_category.php", the "count()" function is called repeatedly on a variable that does not change. For large data sets, this can cause an performance hit.
      Consider changing so that count is called only once:
      From:

      $i = 1;
      while ($originalindex+$i < count($grade_keys)) {
          $possibleitemid = $grade_keys[$originalindex+$i];
          $i++;
      ...

      To:

      $i = 1;
      $gradekeycount = count($grade_keys);
      while ($originalindex+$i < $gradekeycount) {
          $possibleitemid = $grade_keys[$originalindex+$i];
          $i++;
      ...

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Jan/13