Page MenuHomePhabricator

[Task] Lazy initialize LanguageFallbackChain in LinkBeginHookHandler
Closed, ResolvedPublic

Description

Instantiating the LanguageFallbackChain object is somewhat performance intensive.

there are numerous situations (e.g. wikitext page) where we cut short in LinkBeginHookHandler::doOnLinkBegin. In these cases, we shouldn't bother with creating the LanguageFallbackChain here, and only create it when we need.

instead we can inject the LanguageFallbackChainFactory in the class.

Event Timeline

aude raised the priority of this task from to Medium.
aude updated the task description. (Show Details)
aude added projects: Wikidata, Performance Issue.
aude subscribed.

i sometimes get out of memory errors when loading a page, with fresh code base (recaching localisation stuff + doing wikibase stuff).

this may indicate problem areas in our code that we could optimize. :) in this case, I was loading Special:Specialpages which is really not something our LinkBeginHookHandler should be interested in.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /Library/WebServer/Documents/php-master/vendor/wikimedia/cdb/src/Writer/PHP.php on line 124
Call Stack
# Time Memory Function Location
1 0.0001 252472 {main}( ) ../index.php:0
2 0.1061 14741432 MediaWiki->run( ) ../index.php:46
3 0.1061 14742872 MediaWiki->main( ) ../MediaWiki.php:414
4 0.1287 17806896 MediaWiki->performRequest( ) ../MediaWiki.php:566
5 3.4906 27725608 SpecialPageFactory::executePath( ) ../MediaWiki.php:267
6 3.4918 27910064 SpecialPage->run( ) ../SpecialPageFactory.php:581
7 3.5009 29376672 SpecialSpecialpages->execute( ) ../SpecialPage.php:384
8 4.3192 60631568 SpecialSpecialpages->outputPageList( ) ../SpecialSpecialpages.php:49
9 4.3295 61520648 Linker::linkKnown( ) ../SpecialSpecialpages.php:129
10 4.3295 61521720 Linker::link( ) ../Linker.php:266
11 4.3295 61523528 Hooks::run( ) ../Linker.php:212
12 4.3299 61580960 call_user_func_array:{/Library/WebServer/Documents/php-master/includes/Hooks.php:209} ( ) ../Hooks.php:209
13 4.3300 61581952 Wikibase\Repo\Hooks\LinkBeginHookHandler::onLinkBegin( ) ../Hooks.php:209
14 4.3300 61582096 Wikibase\Repo\Hooks\LinkBeginHookHandler::newFromGlobalState( ) ../LinkBeginHookHandler.php:96
15 4.3300 61582224 Wikibase\LanguageFallbackChainFactory->newFromContext( ) ../LinkBeginHookHandler.php:68
16 4.3300 61582448 Wikibase\LanguageFallbackChainFactory->newFromUserAndLanguageCode( ) ../LanguageFallbackChainFactory.php:203
17 4.3468 61804984 Wikibase\LanguageFallbackChainFactory->buildFromBabel( ) ../LanguageFallbackChainFactory.php:239
18 22.6063 106598688 Wikibase\LanguageFallbackChainFactory->buildFromLanguage( ) ../LanguageFallbackChainFactory.php:323
19 22.6063 106599168 Language::getFallbacksFor( ) ../LanguageFallbackChainFactory.php:187
20 22.6063 106599264 LocalisationCache->getItem( ) ../Language.php:4358
21 22.6064 106599264 LocalisationCache->loadItem( ) ../LocalisationCache.php:260
22 22.6064 106599264 LocalisationCache->initLanguage( ) ../LocalisationCache.php:323
23 22.6188 106871336 LocalisationCache->recache( ) ../LocalisationCache.php:449
24 25.6569 132406400 LCStoreCDB->set( ) ../LocalisationCache.php:1011
25 25.6569 132406544 Cdb\Writer\PHP->set( ) ../LocalisationCache.php:1327
26 25.6570 132406688 Cdb\Writer\PHP->addend( ) ../PHP.php:74

aude renamed this task from Lazy initialize LanguageFallbackChain in LinkBeginHookHandler to [Task] Lazy initialize LanguageFallbackChain in LinkBeginHookHandler.Aug 13 2015, 9:12 PM
aude set Security to None.
Addshore claimed this task.
Addshore subscribed.

Looking at the code now I don't immediately spot this issue so going to resolve.