1st up, awesome product!
During our rollout and testing, we noticed a performance issue in loading certain article pages. We tracked the issue down to glossary processing during the rendering of a an article.
Basically, if you have a non-trivial number of glossary items (>100) with a non-trivial article (>250 words), processing of the page can take 180 - 300 seconds depending on the actual word count of the article. The actual performance bottleneck is occurring in /inc/PMF/Glossary.php in the insertItemsIntoContent function (line 109 in .22 version)
The PMF_String::preg_replace_callback is a very CPU intensive string processor within a rather tight loop. We were able to drop execution time from 180-300 down to 5 - 10 seconds by pre-checking the content for the glossary term prior to performing the string replacement. The final code looks like this:
if(PMF_String::strpos($content, $item['item']) !== FALSE) {
$content = PMF_String::preg_replace_callback(
'/'
// a. the glossary item could be an attribute name
.'('.$item['item'].'="[^"]*")|'
// b. the glossary item could be inside an attribute value
.'(('.implode('|', $attributes).')="[^"]*'.$item['item'].'[^"]*")|'
// c. the glossary item could be everywhere as a distinct word
.'(\W+)('.$item['item'].')(\W+)|'
// d. the glossary item could be at the beginning of the string as a distinct word
.'^('.$item['item'].')(\W+)|'
// e. the glossary item could be at the end of the string as a distinct word
.'(\W+)('.$item['item'].')$'
.'/mis',
array($this, 'setTooltip'),
$content,
1
);
}
The new code is if(PMF_String::strpos($content, $item['item']) !== FALSE) { [Original replace code] }
Hopefully this helps others!
Recommended performance enhancement
Moderator: Thorsten
Re: Recommended performance enhancement
Hi,
which PHP version do you use?
bye
Thorsten
which PHP version do you use?
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Re: Recommended performance enhancement
Hi,
okay, do you have Zend Opcache enabled?
bye
Thorsten
okay, do you have Zend Opcache enabled?
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist