Reduce amount of code loaded in MwEmbedSupport and TimedMediaHandler startup and BeforePageDisplay
Closed, ResolvedPublic

Description

Whenever possible, modules should be loaded on demand (e.g. specific pages, or in response to a user action), not in startup. If startup modules are needed, they should be as svelte as possible.

MwEmbedSupport.hooks.php adds five, some of which have their own dependencies: https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FMwEmbedSupport.git/45a59b6ee3b9de6dc764cbd3fd6c9d7b3139718b/MwEmbedSupport.hooks.php#L28


Version: master
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=47145

bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz55550.
Mattflaschen created this task.Via LegacyOct 10 2013, 8:16 AM
Mattflaschen added a comment.Via ConduitOct 10 2013, 9:18 AM

The same goes for BeforePageDisplay in TimedMediaHandler. BTW, I'm fine with splitting this bug, but there is no component for MwEmbedSupport yet.

gerritbot added a comment.Via ConduitOct 10 2013, 9:29 AM

Change 88943 had a related patch set uploaded by Mattflaschen:
Remove dialogFitWindow and jquery.ui.dialog from mwEmbedUtil

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

gerritbot added a comment.Via ConduitOct 10 2013, 9:34 AM

Change 88944 had a related patch set uploaded by Mattflaschen:
Correct mw.PopUpMediaTransform dependency

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

Mattflaschen added a comment.Via ConduitOct 10 2013, 9:39 AM

On my local wiki, those are enough to stop it from loading jquery.ui.dialog (and all of its dependencies, e.g. jquery.ui.core) on unrelated pages (e.g. the Main Page).

Thanks to Ori for his new mw.loader.inspect method which led me into checking this out.

Mattflaschen added a comment.Via ConduitOct 10 2013, 9:42 AM

https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FTimedMediaHandler.git/af412751c8bea1012f9715c16d49ffa5ca29f7aa/TimedMediaHandler.hooks.php#L350 is also double-loading the mw.PopUpMediaTransform CSS.

I'm pretty sure the CSS is useless without the JavaScript. If so, I think the addModuleStyles can be removed.

gerritbot added a comment.Via ConduitOct 11 2013, 2:31 PM

Change 88944 merged by Mdale:
Correct mw.PopUpMediaTransform dependency

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

Spage added a comment.Via ConduitOct 26 2013, 7:02 AM

Matt, great sleuthing.

I agree the

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

is redundant, also probably

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

for the similar parser hook.

TMH's BeforePageOutput hook loads 'mw.PopUpMediaTransform', which specifies the dependency on 'mw.MwEmbedSupport'. But MwEmbedSupport in addStartupModules() explicitly loads 'mw.MwEmbedSupport' and all the files that it depends on. I think none of that should be necessary with latest MediaWiki, maybe it's there for backward compatibility with 1.17. I submitted gerrit 92052.

gerritbot added a comment.Via ConduitOct 26 2013, 7:06 AM

Change 88943 merged by jenkins-bot:
Remove dialogFitWindow and jquery.ui.dialog from mwEmbedUtil

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

MZMcBride added a comment.Via ConduitOct 29 2013, 3:31 PM

It looks like https://gerrit.wikimedia.org/r/88943 and https://gerrit.wikimedia.org/r/88944 have been merged. I suppose we're waiting on https://gerrit.wikimedia.org/r/92052 to be merged in order to mark this bug as resolved/fixed.

Mattflaschen added a comment.Via ConduitOct 31 2013, 4:45 AM

This will stop jquery.ui from loading by default on some WMF wikis. Specifically, those where only jquery.mwEmbedUtil depends on jquery.ui.dialog, and nothing else depends on the part of jquery.ui in question.

For gadgets and user scripts, they just need to declare their dependency, either using the gadget syntax or mw.loader.using. Scripts should do this in general.

However, I thought of another issue. If sites are using jquery.ui buttons in regular wikitext, that will also stop working unless jquery.ui.button is loaded some other way (e.g. English Wikipedia has ext.gadget.teahouse loaded by default, and it depends on jquery.ui.button).

See https://en.wikipedia.org/wiki/Template:Clickable_button_2 for an example of this in use.

This will roll out with 1.23wmf2, which means it hits the first non 'test' wiki on the 4th. I'll also send out an email to wikitech-ambassadors about this.

ori added a comment.Via ConduitOct 31 2013, 5:02 AM

(In reply to comment #10)

This will stop jquery.ui from loading by default on some WMF wikis.
Specifically, those where only jquery.mwEmbedUtil depends on
jquery.ui.dialog,
and nothing else depends on the part of jquery.ui in question.

Well done! This is fantastic work.

Krinkle added a comment.Via ConduitNov 5 2013, 12:50 AM

(In reply to comment #7)

Matt, great sleuthing.

I agree the

$out->addModuleStyles( 'mw.PopUpMediaTransform' );

is redundant, [..]

TMH's BeforePageOutput hook loads 'mw.PopUpMediaTransform'
[..] I submitted Gerrit change #92052.

One thing to keep in mind when "fixing" issues like this is the styling if non-JavaScript elements (eg. PHP-served HTML output) as, unless position/top is set these modules will load async and would cause a FOUC.

Of course, that doesn't justify silly code that loads the stylesheet twice but it isn't always obvious that one can simply be removed.

gerritbot added a comment.Via ConduitDec 6 2013, 8:01 AM

Change 99597 had a related patch set uploaded by Ori.livneh:
Don't load mw.PopUpMediaTransform unconditionally

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

gerritbot added a comment.Via ConduitJan 21 2014, 3:01 AM

Change 99597 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

gerritbot added a comment.Via ConduitJan 21 2014, 3:34 AM

Change 108649 had a related patch set uploaded by Ori.livneh:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

gerritbot added a comment.Via ConduitJan 21 2014, 3:37 AM

Change 108650 had a related patch set uploaded by Ori.livneh:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

gerritbot added a comment.Via ConduitJan 21 2014, 3:37 AM

Change 108649 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

gerritbot added a comment.Via ConduitJan 21 2014, 3:37 AM

Change 108650 merged by jenkins-bot:
Only load mw.PopUpMediaTransform on pages that plausibly need it

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

Aklapper added a comment.Via ConduitMar 13 2014, 11:42 AM

All patches merged -> resetting status.

Is more work planned to do here, or shall this be closed as FIXED?

Mattflaschen added a comment.Via ConduitMar 21 2014, 8:32 PM

Marking FIXED. If another part is found and we want a bug, someone can re-open or file something more specific.

ori added a comment.Via ConduitApr 20 2014, 11:02 PM

Not fixed: MwEmbedSupport.hooks.php still says "TODO look into loading this on-demand instead of all pages", as well it should. There is no reason for loading these modules on all pages: 'mw.MwEmbedSupport.style', 'jquery.triggerQueueCallback', 'Spinner', 'jquery.loadingSpinner', 'jquery.mwEmbedUtil', 'mw.MwEmbedSupport'.

Re-opening and bumping priority, for two reasons:

  1. It's a site performance issue. A longstanding one, but no less severe for it.
  2. The hook that it depends on the ResourceLoaderGetStartupModules hook, which is deprecated as of Ic48ad39c6.
gerritbot added a comment.Via ConduitJul 11 2014, 5:02 PM

Change 145584 had a related patch set uploaded by Gilles:
Load most of TMH and its dependencies on demand

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

gerritbot added a comment.Via ConduitJul 11 2014, 5:03 PM

Change 145583 had a related patch set uploaded by Gilles:
Load most of TMH and its dependencies on demand

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

gerritbot added a comment.Via ConduitJul 11 2014, 8:02 PM

Change 145584 merged by jenkins-bot:
Load most of TMH and its dependencies on demand

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

gerritbot added a comment.Via ConduitJul 11 2014, 8:02 PM

Change 145583 merged by jenkins-bot:
Load most of TMH and its dependencies on demand

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

Gilles added a project: Multimedia.Via WebDec 4 2014, 9:22 AM
Gilles raised the priority of this task from "High" to "Unbreak Now!".Via WebDec 4 2014, 10:11 AM
Gilles moved this task to Closed on the Multimedia workboard.
Gilles lowered the priority of this task from "Unbreak Now!" to "High".Via ConduitDec 4 2014, 11:20 AM

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.