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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Do multiple use statements across module dependency hierarchies require as little expense as multiple require statements?
by leocharre (Priest) on Jan 10, 2008 at 20:14 UTC | |
by chromatic (Archbishop) on Jan 10, 2008 at 20:41 UTC | |
by tye (Sage) on Jan 10, 2008 at 20:56 UTC |