Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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 (Bishop) 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
[LanX]: Network (1976 film) yeah
[LanX]: yeah, we just had a discussion at work that SciFi in the 70s had more inovation
[LanX]: (movies)
[Your Mother]: Real ideas. Ideas grounded in reality as well.
[LanX]: still some good newer ones. Oblivion had a great design, Moon was well acted
[Your Mother]: Moon was mind bending and lovely and what's his nose Sam is *always* fun.
[LanX]: the new BS Galactica series is my all time SoapFiction favourite ...
[Your Mother]: I even liked "The Arrival" and I generally hate time travel (oriented) stuff.
[Your Mother]: Gotta go. Stay out of trouble.
[LanX]: no worries ... mainland Europe is safe ;-P

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2018-03-19 15:08 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.