0

I have a website accessible in multiple languages and I'm seeing something strange in my page load times with the different locales. Here are the load times of one of the more important pages as an example.

en_GB = 469ms
fr_BE = 545ms
nl_BE = 1.45s

I already figured out that the difference is caused by this code:

    $format_number = Zend_Locale_Format::toNumber(
        $number,
        array( 'precision' => 2 , 'locale' => Zend_Registry::get( 'Zend_Locale' ) )
    );

If I remove this code and just return the numbers unformated, all 3 locales render the page in about the same time. (+/- 500ms) I have quite a few numbers that need formatting on this page, so hence the serious impact.

I have been looking at this for quite some time now but can't find a solution, or even an explanation at that.

Any ideas?

Peter
  • 1,211
  • 4
  • 17
  • 32

2 Answers2

0

Are you calling Zend_Registry::get('Zend_Locale') multiple times on that page or is it called only once? You said you have quite a few numbers to format on that page. Try setting the registry value to a variable once at the beginning of your page or even in your controller:

$currLocale = Zend_Registry::get('Zend_Locale');

If you are indeed calling Zend_Registry multiple times for the same value you're essentially doing the same thing over and over again.

There could also be some "deeper" difference between the internal workings of the locales themselves. Are you using UTF-8 based locales or what? This is very important as some locales could be containing much more symbols than others. There could also be an specific known/unknown issue with this set of locales on a specific OS. What OS are you running this under?

Borislav Sabev
  • 4,776
  • 1
  • 24
  • 30
  • Yes, I'm calling the ::get more then once. I ::set it using a plugin and predispatch. Then whenever I need it, I call it. In this case, I need it in a view helper. So each time the Zend_View_Helper_Numbers is called, so is the ::get. But then again, isn't that the very reason of Zend_Registry? To make data available throughout the different classes need at that moment? Besides, they are called as often in say en_GB then in nl_BE. I'm indeed using UTF-8 – Peter Jul 08 '13 at 07:45
0

I've just hit this performance hog myself and well.. there is no workaround. Except for using cache, preferably with APC backend. File based cache didn't help for me. You can try setting this(somewhere in bootstrap):

    $frontendOptions = array(
        'lifetime' => null,                   // no expiration
        'automatic_serialization' => false  // this is the default anyways
    );

    $backendOptions = array('cache_dir' => SITE_ROOT.'/cache');

    $cache = Zend_Cache::factory('Output','File',$frontendOptions,$backendOptions);

    Zend_Locale::setCache($cache);

Maybe it will help for you.

For me, date formatting and number formatting takes like 3.5 seconds locally. If I disable these, it takes around a second to get the page, otherwise : ~4.5 second(with file cache enabled, and SSD hard drive).

P.S. Zend_Locale cache is reused for number formatting and all Locale related things.

FDIM
  • 1,981
  • 19
  • 21