Does package C get loaded 3 times?

No.

If C exports into into all three namespaces, does it slow things down?

Yes, exports take time, have a gander at Exporter.pm's source to see what I mean.

Going back to some of my code, I removed some use directives and put them as require directives inside subs and methods. This sped things up a lot for some procedures

This is most likely because use will be executed at compile time, meaning all use statements will be executed (and the modules loaded) no matter where they are (yes, even if they are inside subs). Whereas require will execute at runtime and a require statement within a sub will not be executed until that sub is run.

So I suspect that the speed up you are seeing is that now your modules are being loaded on-demand instead of all at compile time. This essentially spreads out the weight of the module loading (and potentially in some cases, does not do it at all).

Now, if this is a webapp (as you seemed to indicate) and you are planning to deploy this under vanilla CGI, then this kind of optimization is a win. However if you deploy this under mod_perl or FastCGI (or some other "persistent interpreter" solution) then you are better off sticking with use.

-stvn

In reply to Re: Do multiple use statements across module dependency hierarchies require as little expense as multiple require statements? by stvn
in thread Do multiple use statements across module dependency hierarchies require as little expense as multiple require statements? by leocharre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.