Uploaded image for project: 'phpBB3'
  1. phpBB3
  2. PHPBB3-10141

Performance improvement for $auth->_fill_acl()

    XMLWordPrintable

Details

    • Improvement
    • Status: Unverified Fix (View Workflow)
    • Minor
    • Resolution: Fixed
    • 3.0.8
    • 3.0.9-RC1
    • Authentication
    • None
    • All

    Description

      When profiling phpBB $auth->_fill_acl() ended up near the top of the list. I've been looking through this function and it does a LOT of work and a large part of that work is redundant.

      _fill_acl() mainly translates the data in user_permissions in the users table to a bitstring with:

      $this->acl[$f] .= str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT);

      It does this a non trivial amount of times and $subseq is the same on most iterations. My change caches the results for the different subsequences:

      /**
         * Fill ACL array with relevant bitstrings from user_permissions column
         * @access private
         */
         function _fill_acl($user_permissions)
         {  
            $seq_cache = array();
            $this->acl = array();
            $user_permissions = explode("\n", $user_permissions);
       
            foreach ($user_permissions as $f => $seq)
            {  
               if ($seq)
               {  
                  $i = 0;
       
                  if (!isset($this->acl[$f]))
                  {
                     $this->acl[$f] = '';
                  }
       
                  while ($subseq = substr($seq, $i, 6))
                  {
                     if (isset($seq_cache[$subseq]))
                     {
                        $this->acl[$f] .= $seq_cache[$subseq];
                     }
                     else
                     {
                        // We put the original bitstring into the acl array
                        $this->acl[$f] .= ($seq_cache[$subseq] = str_pad(base_convert($subseq, 36, 2), 31, 0, STR_PAD_LEFT));
                     }
                     $i += 6;
                  }
               }
            }
         }
      

      The original _fill_acl() is here:

      https://github.com/phpbb/phpbb3/blob/master/phpBB/includes/auth.php#L129

      In my particular case this resulted in a 200% improvement for this function and a 10% saving in page generation times.

      Attachments

        Activity

          People

            bantu Andreas Fischer [X] (Inactive)
            BartVB BartVB [X] (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: