? Success

User tests: Successful: Unsuccessful:

avatar andrepereiradasilva
andrepereiradasilva
10 Jan 2016

Description

This PR tries to improve performance of JLanguage::parseLanguageFiles (that is called by JLanguage::getKnownLanguages, which is also called by JLanguageHelper::createLanguageList).

It does so by replacing the php RecursiveDirectoryIterator usage by the usage of glob, and other small improvements.

No behaviour should be changed.

Performance Test
PHP with open_basedir
Installed languages Before PR After PR
6 ~110.1 ms ~1.4 ms
5 ~95.5 ms ~1.2 ms
4 ~75.7 ms ~1.1 ms
3 ~58.5 ms ~0.9 ms
2 ~40.5 ms ~0.6 ms
1 ~20.3 ms ~0.4 ms
PHP without open_basedir
Installed languages Before PR After PR
6 ~17.4 ms ~0.9 ms
5 ~14.3 ms ~0.8 ms
4 ~11.2 ms ~0.7 ms
3 ~9.5 ms ~0.5 ms
2 ~6.1 ms ~0.4 ms
1 ~3.2 ms ~0.3 ms

Notes:

  • Tests were made with PHP 5.6 with opcache enabled and in SSD disks. Without opcache and in HDD disks the performance impact is far greater.
  • The huge difference between PHP with or without open_basedir is because when using open_basedir php doesn't cache filesystem paths (even with realpath_cache enabled). More info: https://bugs.php.net/bug.php?id=52312

How to test

  1. Apply this patch.
  2. Go to any view/component/module/plugin that uses JLanguage::getKnownLanguages or JLanguageHelper::createLanguageList. Examples: mod_login in administrator, language code system plugin, com_languages overrides view in administrator and forms language fields.
  3. For instance, for mod_login in administrator, check if the installed language selector is working properly in the admin login screen.

To check the performance improvements, turn on Joomla debugging and check the execution time, before and after the PR.

Observations

Suggestions, code reviews and improvements are welcome.

This could be further improved if we remove the files glob for cycle and the next if. I didn't remove it because i'm not sure if all installed language xml files in Joomla follow the following format: language/zz-YY/zz-YY.xml or language/zzz-YY/zzz-YY.xml. @infograf768 can you confirm this?

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: ?
461591e 10 Jan 2016 avatar andrepereiradasilva cs
avatar infograf768
infograf768 - comment - 11 Jan 2016

This could be further improved if we remove the files glob for cycle and the next if. I didn't remove it because i'm not sure if all installed language xml files in Joomla follow the following format: language/zz-YY/zz-YY.xml or language/zzz-YY/zzz-YY.xml. @infograf768 can you confirm this?

Correct: we use only 2 letters or 3 letters language code + 2 letters country code

Did not test patch yet. Tests should be done on the minimum required version of PHP i.e. 5.3.10

avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

ok.
Don't need fot test now.

Later i will do some improvements them you can test.

Reggarding php 5.3.10 there should be no problem. glob is supported since 4.3.0 (http://php.net/manual/en/function.glob.php). But yes test should be done. Also i think travis does that :).

avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

Also tested Joomla with 3 installed language in admin mod_login view in a host with PHP 5.3.10 (with open_basedir) and HDD disks and, as suspected, the improvement is even bigger:

Host Installed languages Before PR After PR
PHP 5.6.16 (with open_basedir) SSD 3 ~58.5 ms ~0.9 ms
PHP 5.3.10 (with open_basedir) HDD 3 ~168.1 ms ~1.7 ms

Note: tested using php microtime function before/after the code:

public static function parseLanguageFiles($dir = null)
{
    $st = microtime(true);
    // code removed for brevity
    echo number_format(((microtime(true) - $st) * 1000), 4) . ' ms';

    return $languages;
}
avatar infograf768
infograf768 - comment - 11 Jan 2016
avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

or just [a-z]{2,3}-[A-Z]{2} which is even better.

avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

I just have one question, how Joomla treats the directories slash Windows/Linux?
Is there a constant for that?

avatar mbabker
mbabker - comment - 11 Jan 2016

Just use / as PHP itself handles it just fine unless you're doing explicit string comparisons.

avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

Ok. Thanks.
@mbabker, by the way if this PR is approved should i make a PR for Joomla Framework language repository too?

avatar mbabker
mbabker - comment - 11 Jan 2016

Yes

3b3de26 11 Jan 2016 avatar andrepereiradasilva cs
avatar andrepereiradasilva
andrepereiradasilva - comment - 11 Jan 2016

code updated. performance tests updated.

Ok for testing now

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

I have tested this item :white_check_mark: successfully on 3b3de26

Although the speed improvement is not very important, it is real.


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

avatar NLRoosj NLRoosj - test_item - 17 Jan 2016 - Tested successfully
avatar NLRoosj
NLRoosj - comment - 17 Jan 2016

I have tested this item :white_check_mark: successfully on 3b3de26

The login language selector is still working fine; I tested on PHP 5.5.28.


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

avatar dgt41 dgt41 - change - 17 Jan 2016
Status Pending Ready to Commit
avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Jan 2016

2 tests, also already in the framework joomla-framework/language#37, RTC?

avatar joomla-cms-bot joomla-cms-bot - change - 20 Jan 2016
Labels Added: ?
avatar brianteeman
brianteeman - comment - 20 Jan 2016

It was marked RTC by @dgt41 2 days ago


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

avatar andrepereiradasilva
andrepereiradasilva - comment - 20 Jan 2016

oh.ok i just got

joomla-cms-bot added the RTC label 3 minutes ago

avatar wilsonge wilsonge - change - 26 Jan 2016
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2016-01-26 21:13:23
Closed_By wilsonge
avatar wilsonge wilsonge - close - 26 Jan 2016
avatar joomla-cms-bot joomla-cms-bot - close - 26 Jan 2016
avatar wilsonge wilsonge - reference | fbc07b1 - 26 Jan 16
avatar wilsonge wilsonge - merge - 26 Jan 2016
avatar wilsonge wilsonge - close - 26 Jan 2016
avatar joomla-cms-bot joomla-cms-bot - change - 26 Jan 2016
Labels Removed: ?
avatar wilsonge wilsonge - change - 26 Jan 2016
Milestone Added:
avatar andrepereiradasilva andrepereiradasilva - head_ref_deleted - 26 Jan 2016

Add a Comment

Login with GitHub to post a comment