Recommended performance enhancement

Please report bugs here!

Moderator: Thorsten

Post Reply
ArmgaSys
Posts: 7
Joined: Thu May 21, 2015 4:49 am

Recommended performance enhancement

Post by ArmgaSys »

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!
Thorsten
Posts: 15561
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Recommended performance enhancement

Post by Thorsten »

Hi,

which PHP version do you use?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
ArmgaSys
Posts: 7
Joined: Thu May 21, 2015 4:49 am

Re: Recommended performance enhancement

Post by ArmgaSys »

5.5.11
Thorsten
Posts: 15561
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Re: Recommended performance enhancement

Post by Thorsten »

Hi,

okay, do you have Zend Opcache enabled?

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
ArmgaSys
Posts: 7
Joined: Thu May 21, 2015 4:49 am

Re: Recommended performance enhancement

Post by ArmgaSys »

Yes.
Post Reply