phpperformancemagentofallback

What's the performance cost of Magento's fallback mechanism?


Magento has a fallback mechanism that helps prevent errors and theming problems by checking for the existence of expected files through a defined set of paths. It's implemented like this:

/**
 * Check for files existence by specified scheme
 *
 * If fallback enabled, the first found file will be returned. Otherwise the base package / default theme file,
 *   regardless of found or not.
 * If disabled, the lookup won't be performed to spare filesystem calls.
 *
 * @param string $file
 * @param array &$params
 * @param array $fallbackScheme
 * @return string
 */
protected function _fallback($file, array &$params, array $fallbackScheme = array(array()))
{
    if ($this->_shouldFallback) {
        foreach ($fallbackScheme as $try) {
            $params = array_merge($params, $try);
            $filename = $this->validateFile($file, $params);
            if ($filename) {
                return $filename;
            }
        }
        $params['_package'] = self::BASE_PACKAGE;
        $params['_theme']   = self::DEFAULT_THEME;
    }
    return $this->_renderFilename($file, $params);
}

As a Magento theme developer you have two options: You can add as little as possible to your new theme and depend on the fallback, or you can copy everything from the fallback theme into your new theme and modify that (in which case the fallback has to iterate over fewer files before finding its target). The former approach is recommended. The latter is not.

Copying those files is certainly messy, but on the other hand it seems the fallback should be fairly expensive, particularly if (being a good, pithy coder) you make sure as many files fall back as possible. So I find myself wondering if a Magento site will perform better if I take steps to minimize the amount of fallback that happens.

I've searched the web, but haven't found any information about this question, and I'm not yet familiar enough with Magento to profile the fallback myself. Is there any information about the actual performance cost of this fallback mechanism?


Solution

  • The performance cost is 37.

    Less snarkily: Your question is, unfortunately, unanswerable. While there's (obviously) a performance cost to stating those files and directories, Magento (and any LAMP application) will hit performance bottlenecks due to SQL overhead and CPU much sooner than it will due to other factors. Performance tuning of modern web applications tends not to happen on the the application level, but instead treating the application as an unchangeable blob and purchasing/configuring the best possible hardware setup.

    If anyone has benchmarked Magento with fallback on or off, they haven't shared the information publicly.