User tests: Successful: Unsuccessful:
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.
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:
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 |
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 |
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.
I hope i didn't forgot any test, but if anything wrong say so.
Suggestions, code reviews and improvements are welcome.
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
I have tested this item successfully on a15b36d
Overrrides work fine. Language file correctly loaded from extension.
I confirm a gain of about 50%
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?
I have tested this item successfully on a15b36d
It works OK
Status | Pending | ⇒ | Ready to Commit |
RTC - thanks
Labels |
Added:
?
|
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-01-27 22:06:57 |
Closed_By | ⇒ | wilsonge |
Labels |
Removed:
?
|
@infograf768 when you have some time can you test this one too?