? Success

User tests: Successful: Unsuccessful:

avatar andrepereiradasilva
andrepereiradasilva
10 Jan 2016

Description

This PR tries to improve performance of JLanguage::loadLanguage.

It does so by replacing replacing the array_merge by array_replace.

No behaviour should be changed.

Performance

Since JLanguage::loadLanguage is used each time a ini language file is loaded, this PR adds a small performance boost, depending on if you're in the frontend or backend, the language your are using (en-GB or other), and the plugins/components/modules that you have that load language files in the page your viewing.
This small performance boost is for all Joomla pages (frontend, backend, offline, etc).

Some examples of the performance difference in the code changed:

PHP 5.6.16 (opcache enabled)

Sample site with multilanguage. Joomla without cache.

Page INI Files loaded Before PR After PR
Frontpage frontend (en-GB) 11 ~4.3 ms ~1.6 ms
Frontpage frontend (other lang) 22 ~7.3 ms ~2.1 ms
CPanel backend (en-GB) 30 ~16.2 ms ~6.1 ms
CPanel backend (other lang) 60 ~34.7 ms ~11.1 ms
Plugin list backend (en-GB) 47 ~24.9 ms ~8.0 ms
Plugin list backend (other lang) 94 ~45.7 ms ~14.4 ms
PHP 5.3.10 (no opcache)

Ready to production site with multilanguage. Joomla without cache.

Page INI Files loaded Before PR After PR
Frontpage frontend (en-GB) 21 ~20.2 ms ~7.6 ms
Frontpage frontend (other lang) 42 ~43.9 ms ~15.9 ms
CPanel backend (en-GB) 40 ~123.2 ms ~53.9 ms
CPanel backend (other lang) 80 ~202.1 ms ~98.7 ms
Plugin list backend (en-GB) 59 ~123.7 ms ~48.8 ms
Plugin list backend (other lang) 118 ~237.9 ms ~91.2 ms

How to test

  1. Apply this patch.
  2. Check in several languages if the language text is ok (test frontend and backend and multiple views).
  3. Check also language overrides.
  4. Check also if languages are ok in 3rd party extensions.
Testing Performance

Enable the debug and change the code in this PR (https://github.com/joomla/joomla-cms/blob/staging/libraries/joomla/language/language.php#L800-L812) to ...

Before PR:

JDEBUG ? JProfiler::getInstance('Application')->mark('- merging strings from ' . $filename) : null;
if (is_array($strings))
{
    // Sort the underlying heap by key values to optimize merging
    ksort($strings, SORT_STRING);
    $this->strings = array_merge($this->strings, $strings);
}

if (is_array($strings) && count($strings))
{
    // Do not bother with ksort here.  Since the originals were sorted, PHP will already have chosen the best heap.
    $this->strings = array_merge($this->strings, $this->override);
    $result = true;
}
JDEBUG ? JProfiler::getInstance('Application')->mark('- <strong>strings merged</strong>! JLanguage (instance ' . spl_object_hash($this) .') total strings: ' . count($this->strings)) : null;

After PR:

JDEBUG ? JProfiler::getInstance('Application')->mark('- merging strings from ' . $filename) : null;
if (is_array($strings) && count($strings))
{
    $this->strings = array_replace($this->strings, $strings, $this->override);  
    $result = true;
}
JDEBUG ? JProfiler::getInstance('Application')->mark('- <strong>strings merged</strong>! JLanguage (instance ' . spl_object_hash($this) .') total strings: ' . count($this->strings)) : null;

Reload the page and check the debugger Profile Information. (before and after PR). The ones that count are the time (in ms) of the "strings merged" messages in the profile information.

You will notice a slight improvement on each language ini load. Since there are a lot of language ini files, all together the performance improvement is the one i described in the table in this PR.

Observations

I hope i didn't forgot any test, but if anything wrong say so.
Suggestions, code reviews and improvements are welcome.

avatar andrepereiradasilva andrepereiradasilva - open - 10 Jan 2016
avatar andrepereiradasilva andrepereiradasilva - change - 10 Jan 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 10 Jan 2016
Labels Added: ?
avatar andrepereiradasilva
andrepereiradasilva - comment - 15 Jan 2016

@infograf768 when you have some time can you test this one too?

avatar infograf768 infograf768 - test_item - 15 Jan 2016 - Tested successfully
avatar infograf768
infograf768 - comment - 15 Jan 2016

I have tested this item :white_check_mark: successfully on a15b36d

Overrrides work fine. Language file correctly loaded from extension.
I confirm a gain of about 50%


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8875.

avatar andrepereiradasilva
andrepereiradasilva - comment - 26 Jan 2016

This PR (with #8873 that is already RTC) has already been merged in joomla-framework/language#37. Is a performance improvement in all Joomla pages, but especially in pages not in english.

Anyone willing to do a second test?

avatar anibalsanchez anibalsanchez - test_item - 27 Jan 2016 - Tested successfully
avatar anibalsanchez
anibalsanchez - comment - 27 Jan 2016

I have tested this item :white_check_mark: successfully on a15b36d

It works OK


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8875.

avatar brianteeman brianteeman - change - 27 Jan 2016
Status Pending Ready to Commit
avatar brianteeman
brianteeman - comment - 27 Jan 2016

RTC - thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8875.

avatar joomla-cms-bot joomla-cms-bot - change - 27 Jan 2016
Labels Added: ?
avatar wilsonge wilsonge - change - 27 Jan 2016
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2016-01-27 22:06:57
Closed_By wilsonge
avatar wilsonge wilsonge - close - 27 Jan 2016
avatar joomla-cms-bot joomla-cms-bot - close - 27 Jan 2016
avatar wilsonge wilsonge - close - 27 Jan 2016
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jan 2016
Labels Removed: ?
avatar andrepereiradasilva andrepereiradasilva - head_ref_deleted - 27 Jan 2016

Add a Comment

Login with GitHub to post a comment