Search code examples
performancemagentoregistry

Magento register models for performance gain


I have a large application in Magento which is pretty "heavy" in terms of data collections and actions that are performed. Currently I'm trying to optimize the performance and I noticed that during a regular page load, around 900 Mage::getModel calls are being performed. The call itself is quite fast but when 900 calls are made, this affect performance as all the calls take around 2 seconds.

I was wondering if it's safe to use Magento's registry functionality to register models that have no construct arguments. Basically if a Mage::getModel('sales/quote') is called, after loading the class I intend to register the instance under a unique key (like 'model_register_'.className) and all subsequent Mage::getModel('sales/quote') calls will no longer create a new instance of the model but return the one in the registry, which should improve performance. This, of course, would only be used for calls that have no $constructArguments in the Mage::getModel call.

Has anyone done this before? As I am interested if this approach is safe or if this might cause other issues.


Solution

  • Apparently this does not work because registry keeps a reference to the object. So when retrieving the model from the registry, you would not get a "clean" instance