in reply to Use and Require - making an informed choice.
I think it is important to make an informed choice about which of use and require are needed, precicely because which you choose (and where you place requires) has an impact on the percieved performance of your application.
My goal is generally to use modules that will be called early and commonly, but require those called only occasionally. By "commonly" and "occasionally" I mean the answer to the question "in any given run of my app, how likely is it that this particular thing will be called?".
I do this by using require for needed modules at the top of subs that are only occasionally called. As you can imagine, this often gets hard to track. So, as I develop I use modules in each sub, taking advantage of the fact that this will always cause compile-time loads, and won't double-load modules. When I am ready to release a version, I replace certain uses with requires (and calles to import when appropriate), and others I comment out and move to the top of the script. (In fact, I have a commented list of all the requires at the top as well, with an explanation, to help maintainers.)
Now that I've been exposed to autouse, though, I might just autouse modules I'd previously have required, and save the old require for times when I want to avoid calling an import.
|
|---|