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;
$loops++;
}
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.
| Loops |
VAR |
HASH |
HASHREF |
| 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