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

Minor performance improvments in cache::make()

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.1
    • Fix Version/s: 2.6
    • Component/s: Caching
    • Labels:
    • Testing Instructions:
      Hide
      1. Add a calendar subscription. (Home ► Site pages ► Calendar ► Manage subscriptions)
      2. Update the "update frequence" for the subscription.
      3. Delete the calendar subscription.
      4. Make sure no error is noticed during any of the above steps.
      Show
      Add a calendar subscription. (Home ► Site pages ► Calendar ► Manage subscriptions) Update the "update frequence" for the subscription. Delete the calendar subscription. Make sure no error is noticed during any of the above steps.
    • Affected Branches:
      MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE
    • Pull Master Branch:
      MDL-41558-master
    • Sprint:
      BACKEND Sprint 4

      Description

      We are using array_key_exists in a few places in the tree of cache::make() , which is very expensive.
      on my system with the patch the execution time for the following code reduced from 35 ms to 29 ms.

      for ($i = 0; $i < 1000; $i++) {
          $cache = cache::make('core', 'calendar_subscriptions');
      }
      

      This patch should not cause any trouble since $definition should never be null.

      Also while working on this I notcied array_key_exist() usage in cache_definition::set_identifiers(). Although we are never actually storing null values for an identifier, still it could be passed.
      We are storing by typecasting it to a string.

      If we can trust devs not to pass null here, instead pass ''. We can change this instance as well. I have added it as a separate commit. I didn't find any usage in core that pass null as identifier value.

        Attachments

          Activity

            People

            Assignee:
            ankit_frenz Ankit Agarwal
            Reporter:
            ankit_frenz Ankit Agarwal
            Peer reviewer:
            Petr Skoda
            Integrator:
            Sam Hemelryk
            Tester:
            Rajesh Taneja
            Participants:
            Component watchers:
            Matteo Scaramuccia, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              18/Nov/13