Zend_Locale_Format::toNumber very slow in Dutch locale

334 Views Asked by At

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?

2

There are 2 best solutions below

1
Borislav Sabev On

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?

0
FDIM On

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.