12

I measured run time for my page and noticed that the function getBaseCurrencyCode() takes over a second to run. All of my caching are enabled.

I examined the function and saw that the following command:

$this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE)

takes over a second.

but when I use the Mage::getConfig()->getNode(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE); it takes milliseconds

can anyone tell me why is this time difference occurs ?

any advice?


Although I’ve tried the suggested solutions you offered but still there are massive time gaps. I would be happy if you can try and measure the time it takes for you to run the getConfig function and post it here.

I tried measure the time this function takes by wrapping this code with microtime functions

i.e on local path : app\code\core\Mage\Core\Model instead of this line :

$configValue = $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);

I replaced it with this code (same code with microtime):

$start = microtime(true);

$configValue = $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);

$time_elapsed_secs = microtime(true) - $start;

echo "function: getConfig() took me: " .  $time_elapsed_secs . " sec<br />";

die;

my output was:

function: getConfig() took me: 1.1326711177826 sec

I would be happy to see your output and runtime.

4

There are small differences in parsing the config between the 2 but those should not affect performance. Both of the methods just go through a big array to retrieve data.
getConfig actually does some simple calculations and then calls getNode.
The only big difference I see is that $this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE) calls this: $this->_processConfigValue($fullPath, $path, $data);.
This part processes directives marked with {{...}} and at some point the method calls it self under certain circumstances.
Try to benchmark the 2 after you remove the _processConfigValue call.

3

When you call

$this->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE)

It will call

 public function getConfig($path)
    {
        if (isset($this->_configCache[$path])) {
            return $this->_configCache[$path];
        }

        $config = Mage::getConfig();

        $fullPath = 'stores/' . $this->getCode() . '/' . $path;
        $data = $config->getNode($fullPath);
        if (!$data && !Mage::isInstalled()) {
            $data = $config->getNode('default/' . $path);
        }
        if (!$data) {
            return null;
        }
        return $this->_processConfigValue($fullPath, $path, $data);
    }

also

protected function _processConfigValue($fullPath, $path, $node)
    {
        if (isset($this->_configCache[$path])) {
            return $this->_configCache[$path];
        }

        if ($node->hasChildren()) {
            $aValue = array();
            foreach ($node->children() as $k => $v) {
                $aValue[$k] = $this->_processConfigValue($fullPath . '/' . $k, $path . '/' . $k, $v);
            }
            $this->_configCache[$path] = $aValue;
            return $aValue;
        }

        $sValue = (string) $node;
        if (!empty($node['backend_model']) && !empty($sValue)) {
            $backend = Mage::getModel((string) $node['backend_model']);
            $backend->setPath($path)->setValue($sValue)->afterLoad();
            $sValue = $backend->getValue();
        }

        if (is_string($sValue) && strpos($sValue, '{{') !== false) {
            if (strpos($sValue, '{{unsecure_base_url}}') !== false) {
                $unsecureBaseUrl = $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL);
                $sValue = str_replace('{{unsecure_base_url}}', $unsecureBaseUrl, $sValue);
            } elseif (strpos($sValue, '{{secure_base_url}}') !== false) {
                $secureBaseUrl = $this->getConfig(self::XML_PATH_SECURE_BASE_URL);
                $sValue = str_replace('{{secure_base_url}}', $secureBaseUrl, $sValue);
            } elseif (strpos($sValue, '{{base_url}}') !== false) {
                $sValue = Mage::getConfig()->substDistroServerVars($sValue);
            }
        }

        $this->_configCache[$path] = $sValue;

        return $sValue;
    }

and when you call

Mage::getConfig()->getNode(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE)

It will read xml file and return output.

I think As per @Marius sir suggest and it wont affect performance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.