Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Do multiple calls to 'use X' abuse the compiler?

by ikegami (Patriarch)
on Feb 29, 2008 at 16:59 UTC ( [id://671222]=note: print w/replies, xml ) Need Help??


in reply to Do multiple calls to 'use X' abuse the compiler?

use CGI::Application; imports the symbols from CGI::Application (if any) everytime it's executed.
use CGI::Application qw( );, on the other hand, is just a require that occurs at compile-time.
use base doesn't seem to have much overhead.

If I have 10 calls to 'use' in various modules (same namespace definition).. how much of a hit is that for the interpreter?

Benchmark it. It's the only way to know.

Replies are listed 'Best First'.
Re^2: Do multiple calls to 'use X' abuse the compiler?
by diotalevi (Canon) on Mar 02, 2008 at 02:18 UTC

    Quadruple downvotes for saying "Benchmark it" to this question. The real answer is that every use() past the first is only a hash lookup. There's no abuse of the compiler and you should feel very safe in using the same thing from many places.

    Caveats are of course, that $class->VERSION eq '...' or die "..." and $class->import(...) are also possibly implicated but neither of those are compiler tasks and you ought to already know if you care about the overhead of each and whether you're invoking them. I can't imagine someone using CGI::Application is going to care about the additional cost of one cheap method call.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      The real answer is that every use() past the first is only a hash lookup

      I said use Module qw( ); is just a hash lookup, but use Module; isn't. Are you contradicting that?

      you ought to already know if you care about the overhead of each

      How? I heard import can be fairly costly. But to know for sure, one would been benchmark it.

      And whether or not he ought to know is not important. He asked so I answered.

        ->import is frequently extremely cheap especially when it is just Exporter's. Modules are of course free to write their own import and may gmake them as expensive as they wish.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://671222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-26 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found