User tests: Successful: Unsuccessful:
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.
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 |
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:
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
JLanguage::getKnownLanguages
or JLanguageHelper::createLanguageList
.
Examples: mod_login in administrator, language code system plugin, com_languages overrides view in administrator and forms language fields.To check the performance improvements, turn on Joomla debugging and check the execution time, before and after the PR.
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?
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
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 :).
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;
}
You can safely change your preg_match to
([a-z]{2,3})[-]([A-Z]{2})
Ref:
https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_languages/models/language.php#L194
or just [a-z]{2,3}-[A-Z]{2}
which is even better.
I just have one question, how Joomla treats the directories slash Windows/Linux?
Is there a constant for that?
Just use /
as PHP itself handles it just fine unless you're doing explicit string comparisons.
Yes
code updated. performance tests updated.
Ok for testing now
I have tested this item successfully on 3b3de26
Although the speed improvement is not very important, it is real.
I have tested this item successfully on 3b3de26
The login language selector is still working fine; I tested on PHP 5.5.28.
Status | Pending | ⇒ | Ready to Commit |
2 tests, also already in the framework joomla-framework/language#37, RTC?
Labels |
Added:
?
|
It was marked RTC by @dgt41 2 days ago
oh.ok i just got
joomla-cms-bot added the RTC label 3 minutes ago
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-01-26 21:13:23 |
Closed_By | ⇒ | wilsonge |
Labels |
Removed:
?
|
Milestone |
Added: |
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