Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

quick question on modules

by perlaintdead (Scribe)
on Feb 01, 2013 at 09:12 UTC ( #1016481=perlquestion: print w/replies, xml ) Need Help??
perlaintdead has asked for the wisdom of the Perl Monks concerning the following question:

if you load a module like: use something::or::other qw(funt); will it use less memory than just: use something::or::other;

Replies are listed 'Best First'.
Re: quick question on modules
by LanX (Chancellor) on Feb 01, 2013 at 09:38 UTC
    Normally no!

    Use means that a module-function import() is called at BEGIN-time.

    Normally this function is inherited by Exporter module and does only an aliasing of imported functions.

    And aliasing costs only some bytes, not enough to be discussed.

    But a module author can chose to define his own import and do whatever he wants... so no general answer here.

    Cheers Rolf

      A great counterexample is POSIX:

      Q:\>perl -MPOSIX -wle "print for grep {$_ =~ /$$/} `tasklist`" perl.exe 5508 Console 0 3.936 +K Q:\>perl -MPOSIX=strftime -wle "print for grep {$_ =~ /$$/} `tasklist` +" perl.exe 4904 Console 0 3.672 +K exports all its functions and constants by default, which costs 300K memory, while importing just the few needed functions reduces the amount of memory spent.

      tl; dr - just like you said, no general answer here.

Re: quick question on modules
by vinoth.ree (Monsignor) on Feb 01, 2013 at 09:43 UTC

    If you use use something::or::other qw(funt) this method, it will export only funt symbol into the caller namespace.

    If you use use something::or::other method, it will export list of symbols (subroutines and variables) of the module to be exported into the caller namespace from @EXPORT array defined in something::or::other

      The question was "will it use less memory" not "what is the difference between ..."

        The question was "will it use less memory" not "what is the difference between ..."

        And then?

Re: quick question on modules
by perlaintdead (Scribe) on Feb 01, 2013 at 10:03 UTC

    /\ thanks to all above

Re: quick question on modules
by Anonymous Monk on Feb 01, 2013 at 13:17 UTC
    I suspect that it very often comes down to how many things, that are not already used, are brought in by the module being used.
Re: quick question on modules
by dsheroh (Prior) on Feb 02, 2013 at 09:07 UTC
    An important point alluded to, but never explicitly stated, by the earlier answers: The only difference is in which symbols are aliased into the useing module. All of something::or::other will be compiled and kept in memory regardless of whether you only import funt or import all available symbols1. The memory used to load the module's code will dwarf the memory used to alias the exported symbols into the user's namespace, so it's not going to be a significant difference.

    1 If the used module is built around Autoloader/AutoSplit/SelfLoader, this doesn't hold, as they allow the module to only load and compile subs on-demand instead of compiling the whole thing at program start-up. In my experience, though, this isn't done all that often, so it's probably safe to assume that any random module will be loaded in full if used.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1016481]
Approved by Ratazong
[marinersk]: But I was looking for a more elegant solution. It appears noone online at this time is aware of one.
[LanX]: go to Nodelet Settings and click "All nodelets off"
[marinersk]: LanX++ LOL Yes, that is another workaround. :-)
[LanX]: strangely you can't disable the XP nodelet
[LanX]: But you can use CSS to hide it
[LanX]: and disoplay the data permanently in your peronal nodelet
[marinersk]: I saw that you could post it on the Personal Nodelet, but you have to provide the content also. No way to auto-populate it. Not that this would solve my distraction problem...
[LanX]: there are template variables to "Auto-populate" it

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2017-05-29 14:21 GMT
Find Nodes?
    Voting Booth?