Search code examples
phpperformancelazy-loadingapc

Does APC lazy loading increase performance?


PHP's APC extension includes two configuration settings for enabling lazy loading of functions and classes; apc.lazy_functions and apc.lazy_classes.

My websites use APC with noticable performance benefits. They've also had the lazy loading settings enabled and disabled at various times, with no obviously noticable difference.

On the internet there isn't much on the subject other than mere discussion, but no metrics.

Has anybody actually measured the performance impact of using APC lazy loading or are there people who have noticed significant differences using these settings? When is it advantageous to enable lazy loading? When should it be avoided at all cost?


Solution

  • It depends entirely on the type of application you use APC with.

    Most frameworks include autoloading of clases in one way or another. What this basically means is that the apc settings for apc.lazy_functions and apc.lazy_classes is superfluous in the context of dynamically included/required classes on demand.

    There's a shift in coding standards with PHP, especially with the acceptance of PSR-1 Coding Standard, frameworks not only implement autoloading, but also ensure that only one class is defined per file.

    This in turn means that apc.lazy_classes only copy classes from included files as they are used, but current coding standards ensure that files are included as needed and that included files define only one class, that is immediately used.

    Using apc.lazy_functions and apc.lazy_classes with other (older) projects, might give better results.


    However, with regard to apc.lazy_functions, that settings only covers global scope functions defined in files. Not individual methods of classes. The nomenclature might be misleading, but class functions are distinctively called methods.