jk2addict has asked for the wisdom of the Perl Monks concerning the following question:

Is there a guide somewhere on how to start performance tuning a dist? The DProf pod covers how to use the module but doesn't really cover the philosophy and techniques behind actually tuning existing software.

Should I just start dprof-ing the tests in the test suite, or will there be too much noise from the test harness? Should I write generic script files and test each sub one by one? etc, etc, etc. How does everyone out there tackle tuning?

Update: s/perf/prof/


Replies are listed 'Best First'.
Re: DProf-ing A Dist
by Joost (Canon) on Aug 19, 2005 at 18:57 UTC
Re: DProf-ing A Dist
by xdg (Monsignor) on Aug 19, 2005 at 19:06 UTC

    The general idea is that you want to identify where your program spends most of its time and focus your optimization efforts there. (E.g., subroutines that are frequently called or that take a long time to execute.) This is what Devel::DProf (and the dprofpp program) does for you.

    Once you've identified those areas, you want to find out whether there are things in those sections that can be recoded to take less time. (E.g. something that is computed inside a loop the same way every time should be computed once before the loop starts).

    The Wikipedia has an entry on Optimization that might get you started. You might also want to pick up a copy of Jon Bentley's Programming Pearls, which (while not Perl specific, despite the title) has a lot of good insights.


    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: DProf-ing A Dist
by perrin (Chancellor) on Aug 19, 2005 at 19:03 UTC
    Usually you take some real-world code and profile it. If you have no real-world code at this point, it may be too soon to do performance tuning. If you use the test suite, you won't have much perspective on which parts actually need to be faster, so you might waste time tuning something no one cares about.