Issues

ZF-2999: performance optimization

Issue Type: Improvement Created: 2008-03-31T14:10:11.000+0000 Last Updated: 2008-09-02T10:39:00.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Marc Bennewitz (GIATA mbH) (mben) Assignee: Thomas Weidner (thomas) Tags: - Zend_Locale

Related issues: Attachments:

Description

<pre class="highlight">
isset(self::$_localeData[$locale])
// instead of
array_key_exists($locale, self::$_localeData)
<pre class="highlight">
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
  1. cache return value of getBrowser and if the environment variable must changable add an argument e.g. $reparse=false

Comments

Posted by Wil Sinclair (wil) on 2008-03-31T14:55:04.000+0000

Could you please evaluate and categorize as necessary.

Posted by Thomas Weidner (thomas) on 2008-05-26T13:04:51.000+0000

  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.

Posted by Marc Bennewitz (GIATA mbH) (mben) on 2008-05-27T04:13:20.000+0000

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()

<pre class="highlight">
public function getBrowser($reparse=false)
{
    if ($reparse === false && $this->_getBrowserCache !== null) {
        return $this->_getBrowserCache;
    }
    
    // ... parse
    
    return $this->_getBrowserCache;
}

Posted by Thomas Weidner (thomas) on 2008-05-27T10:19:54.000+0000

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.

Posted by Marc Bennewitz (GIATA mbH) (mben) on 2008-05-28T01:03:58.000+0000

Hi Thomas

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

Zend_Locale:

<pre class="highlight">
public function getBrowser()
{
    echo " - getBrowser called\n";
    // ...
}

testscript:

<pre class="highlight">
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:

<pre class="highlight">
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

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:00.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts