archive_me1Add my vote for this tag coding_style1Add my vote for this tag performance1Add my vote for this tag create new tag
, view all tags
Next to installation difficulties, the most often-quoted reason for non-adoption of TWiki - and the most often quoted for subsequent un-adoption - is performance. This is an interesting and complex problem that has many contributory factors. This page focuses on only one aspect of performance, specifically how your Perl coding style affects it.

It has been represented by several people that the use of an OO coding style may have a strongly negative impact on performance. I have been curious as to why people think this for some time, as it runs counter to my personal experience. However, one aspect that may concern people is that frequent use of HASH references may have an impact. The following, which is entirely based on MichaelSparks' work in http://www.owiki.org/HashRefsVsGlobals, would tend to refute this view.

Languages like Perl are optimised for regexes over hashref values. Trivial programs like:

while( time-$y < 5 ) { 
   $x += 1; 
print "VAR: ", $x/5.0, "\n";
Show significant speed difference if $x is replaced with $x{quick} or $x->{quick} - the latter 2 being about 25% slower. This kind of simple-minded measurement is what leads people to the conclusion that use of references is inefficient in Perl.

However this is not representative of the operations performed during rendering of a wiki page.

Changing this to something a wiki does often radically changes this result. The table that follows is based on the following:

$manfile = `man man`;
while( time-$y < 100 ) 
   $z->{copy} = $manfile;
   $z->{copy} =~ s/ //go;
   $z->{copy} =~ s/s//go;
print "HASHREF: ", $loops/100.0, " ", length( $manfile ), "\n";

Points varied:

  • The number of regexes was varied from 1 to 60 (1, 5, 9, 20, 60 specifically)
  • Types used were $copy , $z{copy} , $z->{copy} (VAR, HASH, HASHREF below)

In the table below the value is the number of iterations per second for each kind on a relatively slow machine. A bigger result (Loops) is better.

1 82.49 84.79 85.01
5 61.37 61.25 61.31
9 45.87 47.38 46.6
20 27.63 29.77 30.31
60 21.75 21.84 22.64

From this it's pretty clear:

  • hashrefs and hashes aren't slower than simple variables with wiki style workloads
  • They can actually be quicker if you're doing lots of regex work, as wikis do
  • the execution model in Perl is such that the only benchmarks of value are those that model the real behaviour of the application in question

TWiki code has been modified to use a more OO style since this topic was created, so it is no longer relevant. I think we should archive it for future reference only.

-- RafaelAlvarez - 14 Sep 2008

Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2008-09-14 - RafaelAlvarez
  • 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.