Is there any difference in performance between load and the use of collections?
Yes. But to understand that, you should first understand the difference in functionality.
$product = Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*')
does not have the same result as this:
$product = Mage::getModel('catalog/product')->load($item->getId());
Difference for EAV models:
- The entity is loaded from the main table (for products:
- All EAV attributes for this entity are loaded from the respective tables
_afterLoad method and
load_after events are triggered (for products: custom options and inventory data is loaded, other additional data from extensions)
Get From Collection
- For products and categories: If the flat catalog is enabled, the attributes are loaded in a single query from the flat table. But that means, only attributes that are configured as "used in product listing", i.e. in the flat index, are loaded
- Additional data may be joined from other index tables (for products: stock, price, category), but you have to specify that explicitly.
collection_load_after events are triggered
That means, you have more flexibility in collections what to load, but it's never the same as a full load. Understand what you need and decide which option works for you.
A lesser known fact is that you can also restrict the loaded attributes in
load() for EAV models:
$product = Mage::getModel('catalog/product')->load($productId, ['sku', 'name', 'description']);
This way you can:
- force using the EAV tables instead of flat table
- have the
load_after events triggered
- load only what you need and notably increase performance