|
Lagged_Loader
A replacement for Zend_Loader
performance, optimization, autoload, Zend_Loader, Phase-Implementation, Featured IntroductionLagged_Loader may be used to autoload models, controllers and Zend_ classes. Models and controllers from inside modules are also supported. So far a couple basic benchmarks showed a 2.5 - 3x performance boost if you switch to autoloading and apply all suggestions from this page. DetailsInstallationAssuming the following path: /path/to/your/zf/app/library ... executed the following commands: cd /path/to/your/zf/app/library svn export http://lagged.googlecode.com/svn/trunk/Lagged ./Lagged You could also keep track via svn:externals, but I suggest you wait until I "branch off" the code so you're not subject to maybe breaking changes in trunk. AutoloadingThe __autoload() should be setup in your project's bootstrap. Example #1 function __autoload($className)
{
static $loader;
$loader = new Lagged_Loader('/path/to/your/zf/app');
$loader->loadClass($className);
}Example #2 define('LAGGED_APPLICATION_DIR', '/path/to/your/zf/app');
function __autoload($className)
{
Lagged_Loader::loadClass($className);
}RequirementsFor simplicity, the loader expects your Zend Framework code to reside in your projects library/ directory. To gain performance, we are not searching multiple include_path's etc.. As for library code this loader currently supports class code from the Zend_ and Lagged_ namespaces, this is subject to change. Models and controllersIn order to support model and controller loading (along with those in modules), we expect/suggest the standard project layout:
To utilize the loader, replace the Zend_Loader in the framework code: grep -rl require_once . | grep -v svn \
| xargs perl -pi~ -e 's/Zend_Loader::loadClass/Lagged_Loader::load'Lagged_Loader::load() imitates the behaviour of Zend_Loader::loadClass(). To make Lagged_Loader play nice with the regular Zend Framework code base, you need to define the following constant (which saves us more "lookups" and creates absolute paths) for include in your project's bootstrap: // no trailing slash
define('LAGGED_APPLICATION_DIR', '/path/to/project');Notes on development
Further optimizationsTo optimize further, I also suggest you strip require_once from all framework code in order to gain performance: grep -rl require_once . | grep -v svn |grep -v Loader \
| xargs perl -pi~ -e 's/require_once/#require_once/'Where do we go from here?My current todo list includes:
What I won't be doing:
|