First let me say this, I am a big fan of MODX Revolution and in regards to page load time I think Revo out of the box is adequate for most sites as it uses advanced caching techniques and page load times are comparable or better than other MVC CMSs. But the more complex the site the longer time the page takes to load. This should seem like a no brainer as this is true no matter how you a develop website or what language you use, to do more will take more resources. Also for what I am about to propose to some the difference may seem small as to be pointless as I will be proposing a method that will trim anywhere from 1/3 of a second to 3/4 of a second from page load time from non performance tuned servers. But if you are running a complex site or have heavy traffic every millisecond is important.
Hypothesis
The largest remaining bottleneck for MODX is text processing. Creating a method to eliminate or greatly reduce text processing will enhance page load times and the created method will not affect how MODX is used in the MVC design.
Every time you use a MODX tag, like [[*content]], MODX (really PHP) has to process those tags to properly to put in the content. The more tags you use the more time is required for processing.
Example thought process layout
- Create a method that preprocesses Templates, Chunks, TVs and Documents on Save and once saved MODX code is processed into PHP code and saved via the cachemanager.
- When the page is loaded and calls on methods like getChunk() and getTemplate(), they first look for PHP code via the cachemanager and execute it. If no PHP code is found then it will process the MODX code and turn it into PHP code and then run.
Proof of concept
I have implemented this concept in a simple way for the Church Events Calendar extra. When doing my testing I was creating a year view and using the proper MODX methods of Chunks. This means that several Chunks are uniquely processed totaling more than 1200 times! My page load times where more than 2 seconds, to me that is unacceptable. Note my test server is not using APC, memecache or any other similar product. I wrote a very simple class called chunkToPhp. What the class does is covert a chunk in to a PHP function. The created function receives a $properties array and returns a string from concatenated PHP vars and the Chunk HTML. And the results for the Year view with the standard MODX Chunk method takes 2 to 2.3 seconds and when using the chunkToPhp class it is greatly reduced to: 0.8-0.9 seconds. I used firebug to view the time.
Now the chunkToPhp class is very simple and will need to completely redesigned to incorporate input and output filters.
The code:
https://github.com/jgulledge19/Church-Events-Calendar/tree/master/core/components/churchevents/model/churchevents see chunktophp.class.php and mycontroller.class.php for how it is used.
I would love to see this concept implemented in MODX but currently I don’t have the time to do devote to help fully implement this concept. I am hoping that this will inspire some more thought on to how to improve MODX.
Post any comments or thoughts please. Thanks,