Tags:
archive_me1Add my vote for this tag performance1Add my vote for this tag create new tag
, view all tags
I will try to explain the flow used, as I am quite new to perl profiling and flaws in the approach are possible.

metric used

The -d:DProf option was added to bin/view

cairo situation

%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 21.5   0.080  0.090     27   0.0030 0.0033  TWiki::BEGIN
 12.9   0.048  0.046     26   0.0019 0.0018  TWiki::Prefs::PrefsCache::replacePreferencesTags

A function replacePreferencesTags is called many times for a single topic. Inside was

    for( $x = 0; $x < @$keys; $x++ ) {
        $term = qr/%\Q$keys->[$x]\E%/;
        $_[0] =~ s/$regexps->[$x]/$vals->[$x]/ge;
    }

It seems that the regexps are recompiled foreach new line coming in in $_[0]. This is quite slow.

improvement

Remark: I have not fully understood what the replacePreferencesTags function is good for. Especially why it is called many times per topic.

I assumed that the preferences stored in keys are static and can be moved out of the loop. I did this quite mechanically and put the regexp compilation at the places where the

$self->{prefsKeys}
were updated. These were loadPref and some other places.

speed up

%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 16.3   0.060  0.090     27   0.0022 0.0033  TWiki::BEGIN
 13.6   0.050  0.050     23   0.0022 0.0022  TWiki::Plugins::BEGIN
 8.16   0.030  0.120      3   0.0100 0.0399  TWiki::UI::View::BEGIN
 5.44   0.020  0.020     26   0.0008 0.0008  TWiki::Prefs::PrefsCache::replacePreferencesTags
 ..

 2.72   0.010  0.018      5   0.0020 0.0036  TWiki::Prefs::PrefsCache::loadPref

It seems that replacePreferencesTags is more than twice as fast and loadPref is getting slower. Overall it seems to be around 5% faster than before

remarks

I guess the patch needs a review or rework as I did not understand the overall picture. However the approach should be clear to move time consuming stuff like regexp compilations out of the inner loops.

It would help if comments what $_[0] represents (a line, a topic ...) in the functions were added to the code. It is difficult to extract the calling frequencies of the various functions from code inspection.

-- FrankHartmann - 09 Oct 2004

Good work, Frank. I'll have a close look at your patch. If it looks right I'll add it to the latrest rev of LocationLocationLocation.

-- CrawfordCurrie - 09 Oct 2004

Ah, I see what you are doing. This fix has been in subversion for a while now, and anyway in LocationLocationLocation the way these tags gets expanded in has been changed (to search for the %(\w+)% pattern and replace that, instead of the per-variable search)

BTW, for anyone trying this patch, it's against Cairo, not against the subversion head.

Thanks Frank. Keep up the good work! (if you can work against the SVN head, rather than the release, and use AthensMarks to give benchmark data, that would be helpful as well -) )

-- CrawfordCurrie - 10 Oct 2004

Crawford I tried to get AthensMarks working, but I am missing two things:

  • a benchmark script for SVN head
  • an athens release. How do I get this out of SVN?

-- FrankHartmann - 10 Oct 2004

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpm-optimize Prefs.pm-optimize r1 manage 22.9 K 2004-10-09 - 13:07 FrankHartmann optimized version of Prefs.pm
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2005-02-14 - SamHasler
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.