Performance of Zend_Loader

I posted a comment on http://blog.digitalstruct.com/2007/12/23/zend-framework-performance-zend... but wanted to go into a little more depth.

When you use Zend_Loader your files are wrapped in conditional statements. These statements prevent APC and all other cache/accelerator programs to have problems properly caching your file.

In a perfect world APC should be able to take all your files and basically internally combined them into a single file, when you use any type of autoload this is not possible because APC doesn't know if that file should be there or not so it has to handle that file EVERY time the page loads.

It should be able to cache the file itself although I am not sure that is always happening but regardless of that it still has to process it into its "internal final product" before execution.

Now here is the catch-22. Depending on the size of your application and how often different classes are used you can run into problems, your memory usage will be higher because all your files are being loaded and depending on how large and the number of classes the overhead to compiling can slow things down.

So is Zend_Loader slow? Of course its slower then just using require but its not the direct cause of the issue, ANY conditional loading of files can reduce the performance of APC, BUT depending on your application the savings of not having to process everything every run might be larger then the performance hit.

Benchmarking is your friend, this is the only way you can know if autoloading will work in your application.

Comments

XCache

Have you read this ?

http://forum.lighttpd.net/topic/864

Is it really say that XCache indeed caches conditional includes ?

Kaloyan

apc_compile_file();

Using apc_compile_file(); is an alternative. I think Facebook works like that - upon restarting the web-server, a script (force-)compiles all the files in advance. In this way the files are already loaded when any script is executing, so conditional-includes are not a draw-back. Anyway, if you are really going to use this approach, you can remove all the conditional-includes anyway, since working with the compiled version of the files is NEVER going to include any of them. So everything depends on the scope of the application, and the "native" environment it is supposed to "live" in. Shared hosting environments are not tend to have APC, so autoloading or using Zend_Loader are really valuable. On the other hand if you run a heavy load web application, autoloading is not the best choice, so using "hardcoded" includes and am opcode cache are the best strategy.

Kaloyan