Zend Framework

performance optimization

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.6.0
  • Component/s: Zend_Locale
  • Labels:
    None
  • Fix Version Priority:
    Nice to Have

Description

1.

isset(self::$_localeData[$locale])
// instead of
array_key_exists($locale, self::$_localeData)

2.

if ( isset(self::$_localeData[$locale])  && ($locale == 'root' || self::$_localeData[$locale] === false) ) {
    // ....
}
// instead of
if (($locale == "auto") or ($locale == "root") or 
    ($locale == "environment") or ($locale == "browser")) {
    // ...
}

// -> OK this isn't for performance but for flexibly

3. cache return value of getBrowser and if the environment variable must changable add an argument e.g. $reparse=false

Activity

Hide
Wil Sinclair added a comment -

Could you please evaluate and categorize as necessary.

Show
Wil Sinclair added a comment - Could you please evaluate and categorize as necessary.
Hide
Thomas Weidner added a comment -

1. has been integrated with r9534 within the I18N core, not only Zend_Locale.

2. brakes existing functionality as it disallows locales like "en_DE" and therefor brakes the downgrading

3. is not necessary as the locale itself is cached, so the browser response has not to be cached alone.

Show
Thomas Weidner added a comment - 1. has been integrated with r9534 within the I18N core, not only Zend_Locale. 2. brakes existing functionality as it disallows locales like "en_DE" and therefor brakes the downgrading 3. is not necessary as the locale itself is cached, so the browser response has not to be cached alone.
Hide
Marc Bennewitz (GIATA mbH) added a comment -

Hi Thomas

Regarding my last statement: it is very slow to parse the result of "$locale->getBrowser()" on every method call, because the clients browser will not change in one connection, but the environment value of "HTTP_ACCEPT_LANGUAGE" can change in one connection during script execution.
To get the array of user accepted locales is not the same as to create a browser locale "new Zend_Locale('browser')".
Furthermore the method getBrowser will be called by getDefault() and the method getDefault() will be called by setLocale()

public function getBrowser($reparse=false)
{
    if ($reparse === false && $this->_getBrowserCache !== null) {
        return $this->_getBrowserCache;
    }
    
    // ... parse
    
    return $this->_getBrowserCache;
}
Show
Marc Bennewitz (GIATA mbH) added a comment - Hi Thomas Regarding my last statement: it is very slow to parse the result of "$locale->getBrowser()" on every method call, because the clients browser will not change in one connection, but the environment value of "HTTP_ACCEPT_LANGUAGE" can change in one connection during script execution. To get the array of user accepted locales is not the same as to create a browser locale "new Zend_Locale('browser')". Furthermore the method getBrowser will be called by getDefault() and the method getDefault() will be called by setLocale()
public function getBrowser($reparse=false)
{
    if ($reparse === false && $this->_getBrowserCache !== null) {
        return $this->_getBrowserCache;
    }
    
    // ... parse
    
    return $this->_getBrowserCache;
}
Hide
Thomas Weidner added a comment -

Locale is locale, independently from the creation.
The locale can change within the same session.

Also if you need the browsers locale you would not parse it again and again.
You would normally store it within your session to reuse it.

Only if you accept that the locale can change within the same session you would parse the locale once more.
And when you use setLocale the browser will only then be parsed when you give one of the autolocales or define that you want to retrieve the autolocale.

In my opinion there is still no benefit of having another option added.

Show
Thomas Weidner added a comment - Locale is locale, independently from the creation. The locale can change within the same session. Also if you need the browsers locale you would not parse it again and again. You would normally store it within your session to reuse it. Only if you accept that the locale can change within the same session you would parse the locale once more. And when you use setLocale the browser will only then be parsed when you give one of the autolocales or define that you want to retrieve the autolocale. In my opinion there is still no benefit of having another option added.
Hide
Marc Bennewitz (GIATA mbH) added a comment -

Hi Thomas

this is a little test script which displays all calls of the getBrowser-method and its output:

Zend_Locale:

public function getBrowser()
{
    echo " - getBrowser called\n";
    // ...
}

testscript:

echo "new Zend_Locale():\n";
$locale = new Zend_Locale();

echo "new Zend_Locale():\n";
$locale = new Zend_Locale();

echo "new Zend_Locale(Zend_Locale::BROWSER);\n";
$locale = new Zend_Locale(Zend_Locale::BROWSER);

echo "\$locale->getDefault();\n";
$locale->getDefault();

echo "\$locale->getDefault(Zend_Locale::BROWSER);\n";
$locale->getDefault(Zend_Locale::BROWSER);

echo "\$locale->setLocale(Zend_Locale::BROWSER);\n";
$locale->setLocale(Zend_Locale::BROWSER);

output:

new Zend_Locale():
 - getBrowser called
 - getBrowser called
 - getBrowser called
 - getBrowser called
new Zend_Locale():
 - getBrowser called
new Zend_Locale(Zend_Locale::BROWSER);
 - getBrowser called
$locale->getDefault();
 - getBrowser called
$locale->getDefault(Zend_Locale::BROWSER);
 - getBrowser called
$locale->setLocale(Zend_Locale::BROWSER);
 - getBrowser called
Show
Marc Bennewitz (GIATA mbH) added a comment - Hi Thomas this is a little test script which displays all calls of the getBrowser-method and its output: Zend_Locale:
public function getBrowser()
{
    echo " - getBrowser called\n";
    // ...
}
testscript:
echo "new Zend_Locale():\n";
$locale = new Zend_Locale();

echo "new Zend_Locale():\n";
$locale = new Zend_Locale();

echo "new Zend_Locale(Zend_Locale::BROWSER);\n";
$locale = new Zend_Locale(Zend_Locale::BROWSER);

echo "\$locale->getDefault();\n";
$locale->getDefault();

echo "\$locale->getDefault(Zend_Locale::BROWSER);\n";
$locale->getDefault(Zend_Locale::BROWSER);

echo "\$locale->setLocale(Zend_Locale::BROWSER);\n";
$locale->setLocale(Zend_Locale::BROWSER);
output:
new Zend_Locale():
 - getBrowser called
 - getBrowser called
 - getBrowser called
 - getBrowser called
new Zend_Locale():
 - getBrowser called
new Zend_Locale(Zend_Locale::BROWSER);
 - getBrowser called
$locale->getDefault();
 - getBrowser called
$locale->getDefault(Zend_Locale::BROWSER);
 - getBrowser called
$locale->setLocale(Zend_Locale::BROWSER);
 - getBrowser called
Hide
Wil Sinclair added a comment -

Updating for the 1.6.0 release.

Show
Wil Sinclair added a comment - Updating for the 1.6.0 release.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
10h
Original Estimate - 10 hours
Remaining:
5h
Time Spent - 5 hours Remaining Estimate - 5 hours
Logged:
5h
Time Spent - 5 hours Remaining Estimate - 5 hours