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

I have an application that heavily uses objects. However, there are a couple of utility modules that are used across the system. I implemented these modules using the exporter. When I ran the profiler, I was surprised to find out that over 20% of the time was spent in the exporter.

Is there a better way to handle utility functions? Should I be using a simple #include? Or, should I convert these functions to objects?

Thanks.
 

Replies are listed 'Best First'.
Re: Exporter alternative?
by perrin (Chancellor) on Apr 03, 2003 at 18:46 UTC
    You are being fooled by DProf. Your program is not actually spending 20% of its time in Exporter. I can't explain why it gets reported this way, but I have seen this before and am very confident that the reported time is not correct.

    There are other reasons you might want to get ride of Exporter. The easiest way to do it is to simply use fully-qualified variable and sub names, like $My::Module::Variable.

Re: Exporter alternative?
by Abigail-II (Bishop) on Apr 03, 2003 at 20:53 UTC
    I'm surprised your program is spending so much time in Exporter. Typically, only at compile time any time is spend in Exporter (when import is called). For a program that "heavily" uses objects, this shouldn't be much of a hassle, as OO programs are relatively slow themselves already. Calling methods is costly, because so much work needs to be done at runtime.

    If you have performance problems, converting functions to objects is the last thing you should do. Objects are slower. Convert your objects into regular function calls. ;-)

    Abigail

Re: Exporter alternative?
by shotgunefx (Parson) on Apr 03, 2003 at 20:46 UTC
    perrin's probably nailed it, but if your Exporter needs are fairly simple you code just use your own and see if it makes a difference.

    -Lee

    "To be civilized is to deny one's nature."
Re: Exporter alternative?
by Anonymous Monk on Apr 04, 2003 at 07:48 UTC
    BTW Rule #1: OO alway pays, keep it. Rule #2: Spent your time about recognizing that with perl in 99% time doesn't count (that much) *sigh*. Why are you so picky about speed ? Murat
Re: Exporter alternative?
by Anonymous Monk on Apr 04, 2003 at 21:43 UTC
    Truth of the matter is, Exporter can get called a lot. Dprof seems to produce a minimal time of 0.0010 for the time something takes.

    A program I use uses hundreds of modules, adding up to 135 calls. 135 * 0.001 == 0.130.. which is 10% for me. Truth of the matter is, it's 135 calls. If you can make your system heavily loaded so you can see how things scale, then you may see Exporter go down to a minimal amount.