amw1 has asked for the wisdom of the Perl Monks concerning the following question:
The problem
We have a reasonably large collection of packages (over 100). We are starting to run into problems with load times and more specifically, the amount of code that needs to be compiled and loaded into memory. The issue stems from the cascade of use statements. Script A uses package B which in turn uses package C which ends up through a huge chain of dependencies 'use'ing 50% of our packages. We end up with a situation where the login page ends up including a module that is entirely unrelated to the login process because one of the modules needed for login needs the unrelated package for a few of its routines.
I am fully aware that this is a hole that we dug for ourselves and that the real answer is to structure our package dependencies in such a way that this doesn't happen. That said, at this point in time the cost to go through and restructure 100k+ lines of code is prohibitive. We are going to be making baby steps to resolve these issues as we have time, but we aren't going to be able to put everything on hold while we fix it.
The idea for a fix
An idea that we've been toying with is to use UNIVERSAL::AUTOLOAD to deal with loading the appropriate packages at runtime. Through some inspection of some of the problem packages it turns out that many of the included packages are included for a function that only gets used in a few specifc places. If those functions aren't called we don't need to load the package.
The important thing to note is we are running CGI's. They load, run, then exit. There is no obvious win by having everything loaded up front. We don't use export very often (for our in house written packages) and we don't use OO functionality in many places either. The other thing to note is that we tend to use fully qualified function names Foo::Bar::func() so we'd be able to reliably figure out what package needs to be used.
The question
We are wondering if there is anything inherantly broken with this approach. At the end of the day the real answer is to re-structure the code to avoid this problem. However, we're looking for something to fix some of our issues before we are able to entirely fix it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dealing with large chains of dependent packages
by jhourcle (Prior) on Aug 01, 2005 at 18:35 UTC | |
|
Re: Dealing with large chains of dependent packages (require)
by tye (Sage) on Aug 01, 2005 at 19:05 UTC | |
|
Re: Dealing with large chains of dependent packages
by 5mi11er (Deacon) on Aug 01, 2005 at 18:33 UTC | |
by djp (Hermit) on Aug 02, 2005 at 03:44 UTC | |
|
Re: Dealing with large chains of dependent packages
by derby (Abbot) on Aug 01, 2005 at 18:49 UTC | |
by techra (Pilgrim) on Aug 01, 2005 at 20:44 UTC | |
|
Re: Dealing with large chains of dependent packages
by Joost (Canon) on Aug 01, 2005 at 20:57 UTC | |
|
Re: Dealing with large chains of dependent packages
by blahblahblah (Priest) on Aug 02, 2005 at 04:11 UTC | |
|
Re: Dealing with large chains of dependent packages
by Anonymous Monk on Aug 02, 2005 at 02:31 UTC |