A lot of mysterious fog surrounds the Magento Compiler, a feature that was introduced in Magento version 1.4.2. According to the original announcement, it realizes 25-50% performance gain. But later Yoav Kutner (Magento chief) said:
In later versions since we optimized the catalog EAV, Magento Compilation is not really needed if you have byte code caching and if it is configured correctly
So is it still useful or not? What does he mean with “configured correctly”? Only one way to find out: descend into the crypts of Magento internals.
First of all, “code compilation” does not refer to converting PHP code into executable machine code. It merely concatenates various PHP files into larger files and stores them in a single location (“includes/src”). Why would anyone want to do that? Because it increases the efficiency of the Autoloader. Normally, upon a request to load a class, the Autoloader looks in four locations to find the appropriate PHP file: app/code/local, app/code/community, app/code/core and finally lib. Useful if you want to overload certain core code with your own version, but slow because of the huge amount of classes scattered around the filesystem.
So the Magento Compiler ensures that the Autoloader only has to look in includes/src and will open less files. A good thing! But how good? Amaze yourself with the following figures.
Setup the Magento Compiler
I defined four testcases, namely with and without APC, with and without the Magento compiler enabled. The target shop is the sample shop running Magento 1.5.1. All types of block caching are enabled. If APC was enabled, this was used as blockcache store, otherwise the file backend was used. I used strace to measure the number of open() system calls and the amount of time spent on disk i/o per pageview. The server uses NFS storage and is otherwise idle. In each testcase I did 5 requests to make sure various caches were primed and subsequently did 30 requests (no concurrency) to measure the average time and number of system calls.
After the results poured in, I was puzzled by the APC-enabled figures. How could Magento spend less time on disk i/o while it opened more files? The difference is apparently in the number of stat64() calls that are greatly reduced by using the compiler mode.
The average speed benefit in using the compiler mode without APC is 100-150 ms.
The average speed benefit in using the compiler mode with APC is 25-30 ms.
So based on average figures, one could confirm Yoav’s statement that the benefit of the compiler with APC is neglectible.
However, one should note that this system was otherwise completely idle and most likely all the filesystem calls were completely cached in local RAM. Previous measurements on normally loaded systems (iowait < 1%) show that when the local filesystem cache is saturated, the speed of stat64() calls can vary greatly, with real world figures of up to 300ms per call. That means that eliminating stat64() calls will reduce i/o performance fluctuation on NFS or other non-dedicated storage. In more human terms: enabling the compiler will eliminate this odd “slow page”.
So the answer is: Yes, use the Magento compiler!