I've noticed that when searching for a particular user's threads, where the first post is long and contains a significant number of nested bbcode tags is really really slow.
I was timing the search results page displaying at 19-25 seconds, to display 25 results as threads. Using xdebug I isolated it down to XenForo_Helper_String::bbCodeStrip calling preg_replace in a loop over the entire message.
Replaced with the following code made the same results page render in 0.5-0.8 seconds.
For a sufficiently long post with enough nested bbcode tags, the current code will spend more time shuffling string data around than anything else.
I was timing the search results page displaying at 19-25 seconds, to display 25 results as threads. Using xdebug I isolated it down to XenForo_Helper_String::bbCodeStrip calling preg_replace in a loop over the entire message.
PHP:
while ($string != ($newString = preg_replace('#\[([a-z0-9]+)(=[^\]]*)?\](.*)\[/\1\]#siU', '\3', $string)))
{
$string = $newString;
}
Replaced with the following code made the same results page render in 0.5-0.8 seconds.
PHP:
$string = self::bbCodeStripTag($string);
...
public static function bbCodeStripTag($string)
{
preg_match_all('#\[([a-z0-9]+)(=[^\]]*)?\](.*)\[/\1\]#siU', $string, $matches, PREG_SET_ORDER);
foreach ($matches as $val)
{
$count = 1;
if (trim($val[3]) != '')
$innerTag = self::bbCodeStripTag($val[3]);
else
$innerTag = $val[3];
$string = str_replace($val[0], $innerTag, $string, $count);
}
return $string;
}
For a sufficiently long post with enough nested bbcode tags, the current code will spend more time shuffling string data around than anything else.
Last edited: