Hi *,
I recently investigated a performance issue with one of Wikibase's test cases. The test in question performed a formatting task for all known languages. While the first assertions ran as fast as expected, they rapidly got slower until finally taking seconds per assertion. I figured this was an actual performance bug (although hardly triggered in production) and started profiling.
My findings, in short:
* The shims for $wgExtensionMessagesFiles as generated by maintenance/generateJsonI18n.php register a handler for the hook LocalisationCacheRecache when included * For every new language loaded, all $wgExtensionMessagesFiles are included by LocalisationCache::recache * Afterwards, LocalisationCache::recache runs the hook LocalisationCacheRecache
This leads to the obvious issue that there is a growing number of registered handlers, which slows down the hook, which slows down the test.
From my point of view, this is a bug. The old approach and the current
implementation of LocalisationCache assume that $wgExtensionMessagesFiles can be included multiple times. However, the $wgExtensionMessagesFiles shims as generated by maintenance/generateJsonI18n.php don't handle this case gracefully.
I can imagine two solutions:
* Fixing the caller (LocalisationCache) by making sure it does not include a single file twice (a simple, finite cache is already implemented in LocalisationCacheBulkLoad). * Fixing the callees ($wgExtensionMessagesFiles) by making sure they register the handler only once. This would need a change to all extensions which already switched to JSON-based localisation.
What do you think?
Adrian Lang
I think technically easiest solution is to modify the i18n.php files:
-$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = function ( $cache, $code, &$cachedData ) { +$GLOBALS['wgHooks']['LocalisationCacheRecache'][__FILE__] = function ( $cache, $code, &$cachedData ) {
This makes it so that if the file is included again, it will just override the previous callback set in that file, instead of adding a new one.
The downside of this approach is that someone needs to change this in all the hundreds of extensions.
Modifying LC itself does not help users like you who are running older versions of MediaWiki [1].
[1] The shims are only used in <= 1.22.
-Niklas
Hi,
On Mon, Apr 14, 2014 at 2:33 PM, Niklas Laxström niklas.laxstrom@gmail.com wrote:
Modifying LC itself does not help users like you who are running older versions of MediaWiki [1].
you are right, although I'm not using an older version of MediaWiki, I'm on 77bc489c2731827b1c61a6509177eed23193d694 from 2014-04-11.
Regards, Adrian
2014-04-14 15:35 GMT+03:00 Adrian Lang adrian.lang@wikimedia.de:
you are right, although I'm not using an older version of MediaWiki, I'm on 77bc489c2731827b1c61a6509177eed23193d694 from 2014-04-11.
Is something loading the i18n files manually then? Or is there a missing $wgMessagesDirs definition matching $wgExtensionMessagesFiles? LC was made so that is skips loading PHP shims when JSON alternative is present.
-Niklas
The files are loaded, only the merging is skipped if JSON-based localisation data is present.
On Mon, Apr 14, 2014 at 3:01 PM, Niklas Laxström niklas.laxstrom@gmail.com wrote:
2014-04-14 15:35 GMT+03:00 Adrian Lang adrian.lang@wikimedia.de:
you are right, although I'm not using an older version of MediaWiki, I'm on 77bc489c2731827b1c61a6509177eed23193d694 from 2014-04-11.
Is something loading the i18n files manually then? Or is there a missing $wgMessagesDirs definition matching $wgExtensionMessagesFiles? LC was made so that is skips loading PHP shims when JSON alternative is present.
-Niklas
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
PleaseStand has already submitted a patch to mitigate this issue in https://gerrit.wikimedia.org/r/#/c/125706/
Please review.
On Mon, Apr 14, 2014 at 2:33 PM, Niklas Laxström niklas.laxstrom@gmail.comwrote:
I think technically easiest solution is to modify the i18n.php files:
-$GLOBALS['wgHooks']['LocalisationCacheRecache'][] = function ( $cache, $code, &$cachedData ) { +$GLOBALS['wgHooks']['LocalisationCacheRecache'][__FILE__] = function ( $cache, $code, &$cachedData ) {
This makes it so that if the file is included again, it will just override the previous callback set in that file, instead of adding a new one.
The downside of this approach is that someone needs to change this in all the hundreds of extensions.
Modifying LC itself does not help users like you who are running older versions of MediaWiki [1].
[1] The shims are only used in <= 1.22.
-Niklas
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
wikitech-l@lists.wikimedia.org