Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Imported subroutines

by rpike (Scribe)
on Sep 16, 2013 at 15:44 UTC ( #1054305=perlquestion: print w/replies, xml ) Need Help??
rpike has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to find ways to speed up my perl web app. I was wondering how exactly @EXPORT and @EXPORT_OK worked when it comes to importing subroutines? I want 3 out of 10 subroutines out of a module - if adding all functions to @EXPORT or to @EXPORT_OK will that slow down processing? Compiling? Thanks in advance for any helpful info regarding this.

Replies are listed 'Best First'.
Re: Imported subroutines
by daxim (Chaplain) on Sep 16, 2013 at 15:55 UTC
    will that slow down processing?
    Yes, it will be unnoticably slower (when import is called, that would be at compile time most of the time) than not exporting.

    However, that's not where the slow part of your program is. Instead use a profiler such as Devel::NYTProf to find out where the real problems are, and optimise those.

Re: Imported subroutines
by davido (Archbishop) on Sep 16, 2013 at 16:13 UTC

    You can look for yourself at the code for Exporter, and see that it's unlikely that adding a few items to the EXPORT list will impact your code's performance meaningfully. If you're facing performance issues, you'll want to look elsewhere. And as daxim said, you should profile rather than take wild guesses.

    Where there may be some benefit is when using modules that autoload or eval subroutines into existence at import time. But even with those sorts of modules, there probably just isn't enough going on to worry about unless your profiling demonstrates a need to investigate this corner of your code base further.

    There are still advantages to exporting/importing only what you need. The most oft-cited one is avoiding namespace pollution in the calling code. Another advantage from the perspective of the calling code is that by specifying exactly which subroutines to import on the use line, the calling code becomes more self-documenting.


Re: Imported subroutines
by Laurent_R (Abbot) on Sep 16, 2013 at 21:50 UTC

    I may be wrong, but my understanding is that when you use or require a module, Perl is compiling the whole module anyway, including the subroutines which are not exported, so that the only difference between exporting or not exporting a function (putting its name in @EXPORT or @EXPORT_OK) would really be updating the program namespace, which probably is not measurable. The fact that you don't export a subroutine does not mean that you don't use it, it only means that it is not intended to be used directly by the main program, but it may very well be used internally by other functions of the same module. Is this view wrong? Am I missing something?

      No, I think that you are exactly correct.   The module will be compiled, regardless, if not done already.   Then, any name in @EXPORT will be added to the global namespace.   If you provide a list of routines in your use statement, they must be in @EXPORT_OK.

      Nothing will lead to any sort of performance problem.   Everything goes through a one-time “compile (on the fly)” process and, once done, never happens again (AFAIK) for the duration of the run.   If there is a performance issue in this app, “red herring ... look elsewhere.”

      I almost never export anything from modules I write. I almost always:

      use Wibble qw();

      when I use modules. I means I have to:


      when I need to call Wobble(), but at least I know where Wobble() lives that way even minutes, or months, after I wrote the code.

      Using OO largely avoids the name space pollution problem that these measures seek to avoid without cluttering the code with explicit name space references.

      True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1054305]
Front-paged by Arunbear
[Corion]: marto: Redoing something on new infrastructure sounds fun. At least you can reuse your previous experience :)
[marto]: I'm looking forwads to it. The video sources are dying, and they don't have the hardware to play them back (old tape formats, not just VHS + Laserdisc etc)
[marto]: I'll be interested to see what difference in terms of file size/quality the new codecs make. I enjoy working on things like this, so that's a bonus
[Corion]: Ah, cool! So it's not an inhouse youtube but for a wider consumption
[marto]: last time it was IE6 clients, now they're on 11, so more scope there also, in terms of UI and playback
[marto]: in house as in Company network, not internet connected (power stations and the corporate HQs)
[Discipulus]: new Monsignor party! free beverages and pizza for all you monks! and a big thanks for the patience you deserved me during these years
[marto]: congrats Discipulus
[Discipulus]: only 4k points to sundial's level ..;=)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2017-07-28 09:19 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (425 votes). Check out past polls.