Page MenuHomePhabricator

Source code eval should be async in mw.loader.work
Closed, ResolvedPublic

Description

Right now in mw.loader.work, before it considers fetching a batch of modules from the server, first:

  1. It iterates over the list and sees if there is an entry in the local cache for that module name and module version.
  2. It gathers all the results, tries to eval them (in one large globalEval call), and then removes those from the batch.
  3. Then, if anything is left, we'll continue doing any fetch(es) for them (which are asynchronous).

Right now step 1 and 2 happen synchronously, sometimes during page load. This is despite that fact that our one and only script-src is asynchronous. The load() command for our module list is inside a deferred script tag (<script>RLQ.push(function)). The execution of that function is managed by the script loaded via script-async-src. However in case of repeat visits, the conditions are usually true:

  • The script-async-src is still non-blocking, but does execute very early on.
  • The script will execute all RLQ inline scripts.
  • It'll enqueue the module names.
  • mw.loader.work will synchronously evaluate any needed scripts we have in local store.
  • Then, and only then, does it create script-src tags for the other modules (which is just a simple createElement and appendChild, rest is asynchronous).

For repeat views, most modules are likely in the local store. This gets much worse after we implement T109837 (consolidating the "top" and "bottom" queues).

Event Timeline

Krinkle moved this task from Inbox to Doing on the Performance-Team board.Aug 5 2016, 1:35 AM
Krinkle updated the task description. (Show Details)Aug 5 2016, 11:33 PM

Change 304158 had a related patch set uploaded (by Krinkle):
[WIP] resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Change 304158 merged by jenkins-bot:
resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Krinkle closed this task as Resolved.Sep 6 2016, 7:38 PM
He7d3r added a subscriber: He7d3r.Oct 3 2016, 2:44 AM

Change 316395 had a related patch set uploaded (by Krinkle):
resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Change 316395 merged by jenkins-bot:
resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Krinkle closed this task as Resolved.Oct 20 2016, 8:39 PM

Change 317283 had a related patch set uploaded (by Krinkle):
resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Change 317283 merged by jenkins-bot:
resourceloader: Make cache-eval in mw.loader.work asynchronous

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

Mentioned in SAL (#wikimedia-operations) [2016-10-24T19:03:33Z] <thcipriani@mira> Synchronized php-1.28.0-wmf.22/resources/src/mediawiki/mediawiki.js: SWAT: [[gerrit:317283|resourceloader: Make cache-eval in mw.loader.work asynchronous (T142129)]] (duration: 00m 52s)