How does Mach II's performance compare to procedural code? - Mach-II/Mach-II-Framework GitHub Wiki
One of the frequent questions that we receive and that comes up often on the Mach-II mailing list concerns performance. The first thing to note about performance is that performance is a very nebulous issue to try and nail down, and performance means different things to different people, so we'll try to address performance as best we can in this FAQ.
First and foremost, realize that even with the performance increases in Adobe ColdFusion 8, object instantiation in CFML is an expensive process. That being said, a well-written and well-architected Mach-II application will perform extremely well, and performance is most certainly not a reason not to use Mach-II. All of the heavily used objects in Mach-II applications are cached in RAM so they do not need to be created every time they are used, so you only pay the time cost for instantiating these objects when the application loads for the first time.
The initial load time of a Mach-II application is not an indication of the performance of the application during runtime. Small to medium Mach-II applications will load in a few seconds to perhaps a minute, and large Mach-II applications may take a couple of minutes or longer to load. As mentioned above, once the application is loaded the application will perform extremely well because of the caching of the framework-controlled objects. Beginning with Mach-II 1.6 you may also take advantage of Mach-II's built-in caching capabilities for very granular control over caching within your application.
Some CFML developers have expressed concerns that building full-blown OO applications in CFML will cause the performance to decrease as compared to traditional procedural CFML applications. In an absolute and very narrow sense, this is true. Procedural code, particularly well-written procedural code, will run faster than an OO application in CFML due to the cost of instantiating objects in CFML. Bear in mind that this does not mean that OO applications in CFML are slow, or even unreasonably slower than procedural applications. Also, compared to a poorly written procedural CFML application, a Mach-II application will perform better due to the caching that is done within the framework.
Also remember that the main priority in writing your application should not be performance. Your main priority during development should be writing for maintainability, which is something writing OO applications and using Mach-II is specifically designed to do. You should never optimize prematurely when writing applications because this may cause you to do strange and unnecessary things as opposed to writing code that is well organized, well architected, and easy to maintain. The procedural vs. OO argument was won long ago so there really is no reason not to be writing OO applications in CFML unless you have very specific needs or reasons for not doing so.
There are two main things to be aware of concerning performance in Mach-II applications. First, make sure that the "config mode" is set appropriately. The config mode is controlled by the variable MACHII_CONFIG_MODE, which is set in Application.cfc. The values for this variable are 1, which causes the application and framework to reload on every request ("development mode"); 0, which will cause the application and framework to load only when the mach-ii.xml configuration file is changed ("dynamic mode"); and -1, which means the application and framework will never reload ("production mode"). Our recommendation is that in most cases you will want to run the framework in "dynamic mode" even when you're developing your application, because this will reduce load times during development. Also note that if MACHII_CONFIG_MODE is set to 0 that any state in your application may be lost on every request, which will likely cause unwanted behavior.
The second thing to be aware of is that if you are profiling the performance of your application using ColdFusion's debugging output, be sure to turn off "report execution times" in the ColdFusion administrator. When report execution time is turned on in the ColdFusion administrator, CFC-heavy applications cause a great deal of performance degradation so the execution times you will see in the debug output do not in any way accurately reflect the actual performance of the application.
The bottom line concerning performance is that Mach-II runs some extremely high-load public applications and these run very well from a performance perspective. We would suggest worrying about performance only when you have to, and only in those areas where it's warranted. By choosing Mach-II you're choosing to create maintainable applications and with the caching in the framework and the new granular caching in Mach-II 1.6, you'll find that performance is extremely fast even under heavy load.