[sf-perl] making perl compile phase faster

Michael Friedman friedman at highwire.stanford.edu
Fri Apr 29 14:14:56 PDT 2011

Well, we only load the modules we need for each script already. We aren't simply using the entire modules directory every time. :-)

The problem is that we have some modules that were written as entire libraries of functions in one file, so to get the one function we need we have to parse all 3700 lines of code. The longer-term solution is, of course, to split these up into separate modules, so we can only load the individual pieces instead of the giant ball of mud. Unfortunately, there's no time in the schedule for that much refactoring. (Yeah, I know. It's called "Technical Debt" and we usually go for the quick and dirty solution. We're paying for it now.)

In the meantime, though, I sure hoped something might help with lazy loading.

MooseX::App::Cmd looks neat, but not so helpful at the moment. However, its POD mentions autouse and Class::Autouse, both of which might be helpful. I'm going to take a look at them and see if I can get at least a few of these modules to lazy load. 

Has anyone used autouse or its like?

-- Mike

Mike Friedman | HighWire Press, Stanford Univ | friedman at highwire.stanford.edu

On Apr 29, 2011, at 1:46 PM, Chris Weyl wrote:

> On Fri, Apr 29, 2011 at 12:30 PM, Michael Friedman <
> friedman at highwire.stanford.edu> wrote:
>> At my site, we run a lot of command-line perl scripts. Unfortunately, we
>> also have 2794 perl modules. Some of our scripts load up thousands of lines
>> of perl code before they can do anything, even display a usage statement.
>> Generally, from the time you hit <return> it's at least 5 seconds before
>> anything happens, often longer, because perl has to load in all the required
>> modules.
> Hm.  Do you actually need these modules loaded?  (I'm guessing not)  One way
> I've dealt with things like this using, e.g., MooseX::App::Cmd and having a
> role wrap execute() in each of the command classes, that then calls
> Class::MOP::load_class() against any modules the command needs to do its
> thing if the command is told to run.  (MX::App::Cmd is just what I tend to
> use; the same methodology would work elsewhere.)  This doesn't do any
> pre-compiling, but helps simply by cutting down to loading only what's
> needed.
> If they're all intertwined and you're looking for a way to make that
> behavior lazy-load, I'm afraid this won't help you at all.  :)
>                                  -Chris
> -- 
> Chris Weyl
> Ex astris scientia

More information about the SanFrancisco-pm mailing list