-
Improvement
-
Resolution: Fixed
-
Minor
-
3.0.8
-
None
-
All
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.