Page MenuHomePhabricator

Cache SnakFormat::getFallbackChain() inside the class
Closed, ResolvedPublic5 Estimated Story Points

Description

For a simple page that doesn't use much data: Wikibase\Lib\Formatters\SnakFormat::getFallbackChain is being called 9000 times, that doesn't make much sense plus the time is spent inside the method is pretty large (40ms) for something close to non-existent. Caching the fallback chain inside the SnakFormat class as a class attribute for now would give a performance boost.

Code: https://github.com/wikimedia/Wikibase/blob/REL1_36/lib/includes/Formatters/SnakFormat.php#L47-L61

Acceptance Criteria🏕️🌟 :

  • Do not regenerate the array returned from SnakFormat::getFallbackChain thousands of times

It was suggested in story time that perhaps this method could be thrown away and the callers reworked to be more efficient

Event Timeline

Addshore set the point value for this task to 5.

I'm not sure if it's worth doing now. Possibly due to lots of refactoring that page I linked is now only call that function 50 times instead of 9k times. Even for Alan Turing category which has a quite large data it calls it 800 times and takes 2ms (in a request taking 13 seconds)
https://performance.wikimedia.org/xhgui/run/symbol?id=610991c3ba89491c5b78b83c&symbol=Wikibase%5CLib%5CFormatters%5CSnakFormat%3A%3AgetFallbackChain
https://performance.wikimedia.org/xhgui/run/symbol?id=610990e8741f6b999e0761ff&symbol=Wikibase%5CLib%5CFormatters%5CSnakFormat%3A%3AgetFallbackChain

Change 710036 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Simplify SnakFormat implementation

https://gerrit.wikimedia.org/r/710036

Change 710036 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Simplify SnakFormat implementation

https://gerrit.wikimedia.org/r/710036