The "CSS Size (Barack Obama - en.m)" graph shows that the CSS size for this page has been fluctuating has been increasing and decreasing cyclically by a consistent amount of bytes for almost a year.
6 month period:
Compare:
http://wpt.wmftest.org/result/180614_EZ_GR/1/details/#waterfall_view_step1 (makes ext.math.styles request
with http://wpt.wmftest.org/result/180612_QJ_GW/1/details/#waterfall_view_step1 (no math request)
The Barack Obama page does not have any Math equations.
I am concerned that user specific preferences are causing parser cache pollution and this problem may be a larger performance problem then we are aware of.
After some investigation (see detailed developer notes) I have managed to narrow this down to a Lua module that reads Wikidata data, which in turn leads to the Math module unexpectedly being added.
Developer notes
Looking at the underlying code there is a troublesome note "This affects the page caching behavior."
https://github.com/wikimedia/mediawiki-extensions-Math/blob/df1689c7177d5b7ef946ae2ff525594bd377da3f/Math.hooks.php#L198
I see the page rendering hash is linked to the user option but not the current user:
https://github.com/wikimedia/mediawiki-extensions-Math/blob/df1689c7177d5b7ef946ae2ff525594bd377da3f/Math.hooks.php#L121
Given the regularity of the CSS change, it seems this isn't related to edit activity so I would suspect there is something funky with the caching here and the style is being added where it shouldn't be.
The style should only be added if the chem or math parser function is used. The only other place ext.math.styles is added relates to Wikidata: Wikidata hook
Replication steps
- Ensure https://wikidata.beta.wmflabs.org/wiki/Q361812 has a site link to https://en.wikipedia.beta.wmflabs.org/wiki/T173949 and has an inception field. IF not add one pointing it to 2017.
- Visit [desktop] https://en.wikipedia.beta.wmflabs.org/wiki/T173949?action=purge incognito and purge page
- Visit [desktop] (hard refresh) https://en.wikipedia.beta.wmflabs.org/wiki/T173949 incognito and verify that mw.loader.getState('ext.math.styles') === 'registered' is true
- Visit [mobile] https://en.m.wikipedia.beta.wmflabs.org/wiki/T173949 and note that mw.loader.getState('ext.math.styles') === 'registered' is now false (Expected: should be true)
- Purge [mobile] https://en.m.wikipedia.beta.wmflabs.org/wiki/T173949?action=purge and verify that mw.loader.getState('ext.math.styles') === 'registered' is still false
- Visit [desktop] https://en.wikipedia.beta.wmflabs.org/wiki/T173949 and see that mw.loader.getState('ext.math.styles') === 'registered' is now false. (Expected: should be true)
- Remove wikilink on https://wikidata.beta.wmflabs.org/wiki/Q361812 to https://en.wikipedia.beta.wmflabs.org/wiki/T173949
- Refresh page and see that mw.loader.getState('ext.math.styles') === 'registered' is now true
Developer notes
This only seems to happen when a page is associated with a Wikidata entry. When I remove the wikilink on https://www.wikidata.org/wiki/Q4115189 the problem magically goes away
It also seems to go away when the template "Internet Archive author" has been removed.
The code inside https://en.wikipedia.org/wiki/Module:Internet_Archive does seem to make use of wikibase - making a call to mw.wikibase.getEntityObject().
I connected https://wikidata.beta.wmflabs.org/wiki/Q361812 to https://en.wikipedia.beta.wmflabs.org/wiki/T173949 and re-ran the experiment but it failed. I updated the module, still no luck, however when I added an inception (start date) field to the Wikidata item the math module started to get pulled in.
Wed 20th June 2018
I've narrowed it down ever further https://en.m.wikipedia.beta.wmflabs.org/wiki/T173949-2 with a simplified module https://en.wikipedia.beta.wmflabs.org/wiki/Module:T173949
All this module does is call the method formatPropertyValues
This method seems to trigger the load of ext.math.styles in the mobile view.
Next step would be to replicate this on an environment where I can see exactly what's going on.
Thur 1st June 2018
I set it up on http://en-reading-web-staging.wmflabs.org/w/index.php?title=T173949 so I could actually debug what's going on.
Discovered the math style was added inside the Math hook. I looked at what introduced this code. It was this patch introduced by T67397.
The onWikibaseClientDataTypes hook is entered in both desktop and mobile for this article but the $dataTypeDefinitions['PT:math'] formatter-factory-callback is only entered on mobile. Why? I'm still investigating. I did a var_dump inside the format-factory-callback for some clues...
object(ValueFormatters\FormatterOptions)[868] protected 'options' => array (size=11) 'languages' => object(Wikibase\LanguageFallbackChain)[834] private 'chain' => array (size=1) ... 'lang' => string 'en' (length=2) 'on-error' => string 'warn' (length=4) 'unDeserializableMessage' => string 'wikibase-undeserializable-value' (length=31) 'geoformat' => string 'dms' (length=3) 'spacing' => array (size=1) 0 => string 'latlong' (length=7) 'directional' => boolean true 'forceSign' => boolean false 'showQuantityUncertaintyMargin' => boolean true 'applyRounding' => boolean true 'applyUnit' => boolean true /vagrant/mediawiki/extensions/Math/src/MathWikidataHook.php:76:string 'text/plain' (length=10)
Looking into this some more - this hook does seem to run on mobile AND desktop and styles are only added on the first run, however only sometimes does it get cached.
Experimenting with several pages, adding styles and scripts at this point in the code seems incorrect and inappropriate given the global usage of wgOut given it doesn't relate to rendering.
Summary
If an article page is connected to a Wikidata entry which has an inception field AND entity:formatPropertyValues( 'P569' ) is invoked inside a Lua module the ext.math.styles module is unexpectedly pulled into the mobile view.
Acceptance criteria
- ext.math.styles should not be loaded on mobile for a page which does not have Math