{"action":"created","issue":{"url":"https://api.github.com/repos/joomla/joomla-cms/issues/8873","labels_url":"https://api.github.com/repos/joomla/joomla-cms/issues/8873/labels{/name}","comments_url":"https://api.github.com/repos/joomla/joomla-cms/issues/8873/comments","events_url":"https://api.github.com/repos/joomla/joomla-cms/issues/8873/events","html_url":"https://github.com/joomla/joomla-cms/pull/8873","id":125829842,"number":8873,"title":"JLanguage::parseLanguageFiles performance improvements","user":{"login":"andrepereiradasilva","id":9630530,"avatar_url":"https://avatars.githubusercontent.com/u/9630530?v=3","gravatar_id":"","url":"https://api.github.com/users/andrepereiradasilva","html_url":"https://github.com/andrepereiradasilva","followers_url":"https://api.github.com/users/andrepereiradasilva/followers","following_url":"https://api.github.com/users/andrepereiradasilva/following{/other_user}","gists_url":"https://api.github.com/users/andrepereiradasilva/gists{/gist_id}","starred_url":"https://api.github.com/users/andrepereiradasilva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrepereiradasilva/subscriptions","organizations_url":"https://api.github.com/users/andrepereiradasilva/orgs","repos_url":"https://api.github.com/users/andrepereiradasilva/repos","events_url":"https://api.github.com/users/andrepereiradasilva/events{/privacy}","received_events_url":"https://api.github.com/users/andrepereiradasilva/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/joomla/joomla-cms/labels/PR-staging","name":"PR-staging","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-10T16:37:51Z","updated_at":"2016-01-11T09:56:38Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/joomla/joomla-cms/pulls/8873","html_url":"https://github.com/joomla/joomla-cms/pull/8873","diff_url":"https://github.com/joomla/joomla-cms/pull/8873.diff","patch_url":"https://github.com/joomla/joomla-cms/pull/8873.patch"},"body":"#### Description\r\n\r\nThis PR tries to improve performance of `JLanguage::parseLanguageFiles` (that is called by `JLanguage::getKnownLanguages`, which is also called by `JLanguageHelper::createLanguageList`).\r\n\r\nIt does so by replacing the php `RecursiveDirectoryIterator` usage by the usage of `glob`, and other small improvements.\r\n\r\nNo behaviour should be changed.\r\n\r\n##### Performance Test\r\n\r\n###### PHP with open_basedir\r\n\r\n| Installed languages   |  Before PR   | After PR    |\r\n|:---------------------:| ------------:| -----------:|\r\n|           6           | ~110.1 ms    | ~3.5 ms     |\r\n|           5           | ~95.5 ms     | ~2.3 ms     |\r\n|           4           | ~75.7 ms     | ~1.9 ms     |\r\n|           3           | ~58.5 ms     | ~1.5 ms     |\r\n|           2           | ~40.5 ms     | ~1.2 ms     |\r\n|           1           | ~20.3 ms     | ~0.7 ms     |\r\n\r\n###### PHP without open_basedir\r\n\r\n| Installed languages   |  Before PR   | After PR    |\r\n|:---------------------:| ------------:| -----------:|\r\n|           6           | ~17.4 ms     | ~2.0 ms     |\r\n|           5           | ~14.3 ms     | ~1.8 ms     |\r\n|           4           | ~11.2 ms     | ~1.5 ms     |\r\n|           3           | ~9.5 ms      | ~1.1 ms     |\r\n|           2           | ~6.1 ms      | ~0.8 ms     |\r\n|           1           | ~3.2 ms      | ~0.5 ms     |\r\n\r\nNotes:\r\n- 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.\r\n- 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\r\n\r\n#### How to test\r\n\r\n1. Apply this patch.\r\n2. Go to any view/component/module/plugin that uses `JLanguage::getKnownLanguages` or `JLanguageHelper::createLanguageList`.\r\n   Examples: mod_login in administrator, language code system plugin, com_languages overrides view in administrator and forms language fields.\r\n3. For instance, for mod_login in administrator, check if the installed language selector is working properly in the admin login screen.\r\n\r\nTo check the performance improvements, turn on Joomla debugging and check the execution time, before and after the PR.\r\n\r\n#### Observations\r\n\r\nSuggestions, code reviews and improvements are welcome.\r\n\r\nThis 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?"},"comment":{"url":"https://api.github.com/repos/joomla/joomla-cms/issues/comments/170493335","html_url":"https://github.com/joomla/joomla-cms/pull/8873#issuecomment-170493335","issue_url":"https://api.github.com/repos/joomla/joomla-cms/issues/8873","id":170493335,"user":{"login":"andrepereiradasilva","id":9630530,"avatar_url":"https://avatars.githubusercontent.com/u/9630530?v=3","gravatar_id":"","url":"https://api.github.com/users/andrepereiradasilva","html_url":"https://github.com/andrepereiradasilva","followers_url":"https://api.github.com/users/andrepereiradasilva/followers","following_url":"https://api.github.com/users/andrepereiradasilva/following{/other_user}","gists_url":"https://api.github.com/users/andrepereiradasilva/gists{/gist_id}","starred_url":"https://api.github.com/users/andrepereiradasilva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andrepereiradasilva/subscriptions","organizations_url":"https://api.github.com/users/andrepereiradasilva/orgs","repos_url":"https://api.github.com/users/andrepereiradasilva/repos","events_url":"https://api.github.com/users/andrepereiradasilva/events{/privacy}","received_events_url":"https://api.github.com/users/andrepereiradasilva/received_events","type":"User","site_admin":false},"created_at":"2016-01-11T09:56:38Z","updated_at":"2016-01-11T09:56:38Z","body":"Also tested Joomla with 3 installed language in PHP 5.3.10 (with open_basedir), in HDD disks and, as suspected, the improvement is even bigger:\r\n\r\n| Installed languages   |  Before PR   | After PR    |\r\n|:---------------------:| ------------:| -----------:|\r\n|           3           | ~168.1 ms    | ~2.5 ms     |\r\n\r\nNote: tested usign php microtime function before/after the code:\r\n\r\n```php\r\npublic static function parseLanguageFiles($dir = null)\r\n{\r\n\t$st=microtime(true);\r\n\t// code removed for brevity\r\n\techo number_format(((microtime(true)-$st)*1000),4);\r\n\r\n\treturn $languages;\r\n}\r\n```"}}