Is there any difference in performance between load
and the use of collections?
I was told that it is better to use this:
$product = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*')
->addAttributeToFilter('entity_id', $productId)
->getFirstItem();
instead of this:
$product = Mage::getModel('catalog/product')->load($item->getId());
Best Answer
Well, the real question here is "what's the difference between
load
and using collections ?"Using collections is a huge performance boost for the following reasons, especially for EAV entities:
When you use the
load
method you load every single attributes assigned to the entity.Let's say you only need to know the value of one attribute of your entity, loading is definitely not the right way to go and should use some code like this:
Worst case scenario is when you use the
load
method in a loop, it can result in a disaster in terms of performances:I suggest you have a look at the following official guide: http://info2.magento.com/rs/magentosoftware/images/Conquer_the_5_Most_Common_Magento_Coding_Issues_to_Optimize_Your_Site_for_Performance.pdf