r9 - 25 Apr 2006 - 10:06:23 - CrawfordCurrieYou are here: TWiki >  Codev Web > PerformanceImprovementsInDakar > CairoAvoidRegexpRecompilation
Tags:
, create new tag

Description

I am trying to optimize the function specificLink in Render.pm as it popped up during my profiling attempts. It looks that some regexps are missing the '/o' modifier. See man perlfaq6.

For getting an overview I tried:


 find . -name '*.pm' -exec grep '$regex' {} /dev/null ';' | perl -ne 's|.*/\w*o\w*\s*[;\)]||;print'

A cleaned subset:


./TWiki.pm:                $line =~ s/([\s\(])($regex{abbrevRegex})/$1<nop>$2/g;    # 'TLA'
./TWiki.pm:                $line =~ s/([\s\(])($regex{webNameRegex})\.($regex{wikiWordRegex})/$1<nop>$3/g;  # 'Web.TopicName'
./TWiki.pm:                $line =~ s/([\s\(])($regex{wikiWordRegex})/$1<nop>$2/g;  # 'TopicName'
./TWiki.pm:        if( $theLink =~ /^($regex{webNameRegex}\.|$regex{defaultWebNameRegex}\.|$regex{linkProtocolPattern}\:)/ ) {
./TWiki.pm:    $_[0] =~ s!%ATTACHURLPATH%/($regex{filenameRegex})!&handleNativeUrlEncode("$pubUrlPath/$_[2]/$_[1]/$1",1)!ge;
./TWiki.pm:    $htext =~ s/(.{162})($regex{mixedAlphaNumRegex})(.*?)$/$1$2 \.\.\./g;
./TWiki.pm:    if ( $fullTopicName =~ $regex{validAsciiStringRegex} ) {
./TWiki.pm:    } elsif ( $fullTopicName =~ $regex{validUtf8StringRegex} ) {
./TWiki.pm:    } elsif( $url =~ /^$regex{linkProtocolPattern}\:/ ) {
./TWiki/Prefs.pm:        $_[0] =~ s/$regexps->[$x]/$vals->[$x]/ge;
./TWiki/Render.pm:      $theLink =~ s/($regex{anchorRegex}$)//;
./TWiki/Render.pm:      $theLink =~ s/^($regex{webNameRegex}|$regex{defaultWebNameRegex})\.//;
./TWiki/Render.pm:    $anchorName =~ s/$regex{singleMixedNonAlphaNumRegex}/_/g;      # only allowed chars
./TWiki/Render.pm:    if ( ! $compatibilityMode && $anchorName =~ /^$regex{anchorRegex}$/ ) {
./TWiki/Render.pm:    if( $theLink =~ /^$regex{linkProtocolPattern}\:/ ) {

BTW Is there an 'best practice' for profiling twiki code? The results I have using -d:DProf are varying a lot even on a unloaded system.

-- FrankHartmann - 09 Oct 2004

Yes, -d:DProf is a pain. See ExaminingPerformance and BetterPerformance.

-- CrawfordCurrie - 10 Oct 2004

Just to review: the main reason to do '/o' on a regex is if there is a variable in the regex AND the regex is used more than once, AND the regex is not already pre-compiled. The variables with names ending in '*Regex' and the contents of the %regex hash should be pre-compiled regexes in any case.

I'm not sure of the benefit of putting '/o' on regexes that are a couple of characters plus a pre-compiled regex - may or may not help, though presumably if the regex is used in a loop or a function like specificLink it is worth doing. Since the complex regexes are already pre-compiled, the win may not be as big as at first sight, but probably worth doing for more complex ones.

-- RichardDonkin - 11 Oct 2004

I have finally managed to get the AthensMarks stuff running. It seems that its worth doing above optimizations.

athens performance = 100 AthensMarks

Release Skin Plugins Time per page AthensMarks
dakar     .3316 23.1000
mattzz     .2850 26.8700

mattzz is Cairo + CairoAvoidRegexpRecompilation + CairoReplacePreferencesTags. It is running at http://mattzz.dyndns.org

Dakar is SVN head as of today. I disabled all plugins, but have a skin active.

-- FrankHartmann - 22 Oct 2004

DEVELOP

DeveloperResponsibilities states a need for cross-references. Here we go.

I started to fix some of the above in the DEVELOP branch:

  • r1807 : TWiki.pm tested with DevelopGoldenReferenceTestConcept. Results in around 1% performace inprovement on my machine with my test topic. Much less in general case.

Thanks Frank - well spotted!

-- CrawfordCurrie - 04 Nov 2004

 

CategoryPerformance

Topic attachments
I Attachment Action Size Date Who Comment
elsepatch Render.patch manage 2.3 K 09 Oct 2004 - 20:02 FrankHartmann diff against Cairo Render.pm
elsepatch TWiki.patch manage 1.4 K 09 Oct 2004 - 20:02 FrankHartmann diff against Cairo TWiki.pm
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r9 < r8 < r7 < r6 < r5 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback SourceForge.net Logo