Page MenuHomePhabricator

Fix missed preload query from ResourceLoader WikiModule on logged-in pageviews
Closed, ResolvedPublic

Description

Pre-existing performance issue, discovered during review of https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1172700 for T393835: Explore removing WikiModuleTitleInfo in ResourceLoader, in favour of standard LinkCache.

On every page view, WikiModule performs two separate database queries instead of one, despite having apparent preloading and batching logic. The first query is the bigger one and originates from the preloader. The second one coveres only one module/page. I suspect the preload in OutputPage has incomplete search critera for its batch, thus not covering the second call in production.

Note that this is not an issue by default in MediaWiki core. The preloader covers all default scenarios in MediaWiki core. The second database query appears specifically when the GlobalCssJs extension is installed, in a more production-like setup (wiki farm with a central wiki).

Example:

  1. Quickstart + Wiki farm on MySQL
    • Wikis: centralwiki, foowiki
    • Config: Database-based session store (so that you can restart the server and stay logged-in). APCU-based cache (so that you can easily clear the MW maincache by simply restarting composer-serve).
    • $wgMainCacheType = CACHE_ACCEL; $wgSessionCacheType = CACHE_DB; $wgDebugToolbar = true;
  2. GlobalCssJs installed with prod-like config.
    • On centralwiki, User:Admin/global.css exists. User:Admin/global.js does not.
  3. Viewing foowiki, logged-in as admin.
  4. Restart (stay logged-in, clear MW maincache).
  5. Hard reload (cold, cache miss) — This performs two database queries to centralwiki from WikiModule instead of one.
  6. Hard reload (warm, cache hit) — Idem, two instead of one.
LocalSettings.php - GlobalCssJs prod-like config
$wgAllowUserCss = true;
$wgAllowUserJs = true;

$wgUseGlobalSiteCssJs = false;
if ( KRINKLE_WIKIFARM ) {
    $wgResourceLoaderSources['centralwiki'] = [
        'apiScript' => 'http://central.localhost:4000/api.php',
        'loadScript' => 'http://central.localhost:4000/load.php',
    ];
    $wgGlobalCssJsConfig['wiki'] = 'centralwiki';
    $wgGlobalCssJsConfig['source'] = 'centralwiki';
}
Queries
USE centralwiki;
SELECT page_namespace,page_title,page_touched,page_len,page_latest FROM page WHERE ((page_namespace = 2 AND page_title = 'Admin/global.css'))

USE centralwiki;
centralwiki SELECT page_namespace,page_title,page_touched,page_len,page_latest FROM page WHERE ((page_namespace = 2 AND page_title = 'Admin/global.js'))

Event Timeline

Change #1225051 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] Output: Preload modules from user group as "user batch" in OutputPage

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

Umherirrender subscribed.

The preload of title information in OutputPage::getRlClient is splitted in a "site batch" and "user batch". The "site batch" contains style modules that not in the "user batch". The "user batch" contains the user.styles module and the user module, but not extensions module in the user group, like the ext.globalCssJs.user and ext.globalCssJs.user.styles module from GlobalCssJs extension.

ext.globalCssJs.user.styles is preloaded as part of the "site batch" (and needs a own query to the centralwiki from this batch due to separate domain)
ext.globalCssJs.user is not preloaded, but ClientHtml::getData calls isKnownEmpty for all modules in the user group, results in the extra query the task seems to be about.

To combine the query in the preload all modules in the user group must be part of the "user batch" to match what ClientHtml needs

Change #1235367 had a related patch set uploaded (by Krinkle; author: Umherirrender):

[mediawiki/core@master] Output: Combine preload of title information for user and site modules

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

Change #1198417 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] ResourceLoader: Improve WikiModule title info preload on OutputPage

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

Change #1235367 abandoned by Umherirrender:

[mediawiki/core@master] Output: Combine preload of title information for user and site modules

Reason:

Fixed as part of I042daa6c42e8a8d530e0b0c752e3830b98395b18

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

Change #1225051 abandoned by Umherirrender:

[mediawiki/core@master] Output: Preload extensions modules from 'user' group in OutputPage

Reason:

Fixed as part of I042daa6c42e8a8d530e0b0c752e3830b98395b18

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

Change #1198417 merged by jenkins-bot:

[mediawiki/core@master] ResourceLoader: Improve WikiModule title info preload on OutputPage

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