Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Function Calls: The Worst Offenders
 
Mark_Kimsal
Sr. Member
 
Total Posts:  186
Joined:  2007-09-12
Michigan, USA
 

Here are some good cases for short-circuiting the getData() and setData() calls…

setData()  called 6,732 times on the home page

Varien_Object 
:: addData() => 5,381 
Mage_Eav_Model_Entity_Attribte_Abstract 
:: setAttributeModel() => 204
Mage_Eav_Model_Entity_Attribte_Abstract 
:: setBackendModel() => 233
Suggestion:  Short-circuit the setData call in addData()

public function addData($arr)
    
{
        
foreach($arr as $index=>$value{
            
if(is_array($index)) {
                $this
->_data $index;
            
else {
                $this
->_data[$index] $value;
            
}
//            $this->setData($index, $value);
        
}
        
return $this;
    
}
This fix is actually pretty weird, it’s a direct copy and paste of setData’s internals, but I highly doubt someone would wrap an array in an array and pass it to addData().  But… you never know.

getData()  called 4,662 times on the home page

Mage_Eav_Model_Entity_Attribte_Abstract 
:: getBackendType() 1,152
Mage_Eav_Model_Entity_Attribte_Abstract 
:: getAttributeCode() 967
Mage_Eav_Model_Entity_Attribte_Abstract 
:: getBackendModel() 512

Short-circuiting each of these functions shouldn’t disrupt any expected behavior because they are so high on the hierarchy chain.  Suggested fix is something like this

public function getBackendType()
    
{
        
return (isset($this->_data['backend_type'])) ? $this->_data['backend_type'null;
//        return $this->getData('backend_type');
    
}

I squozed another 30 milliseconds per request to the front page by hardening up these 6 methods.  At 330 mills initially, that’s almost 10%. (isn’t it?)

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top