Page MenuHomePhabricator

LESS compilation in startup module due to ResourceLoaderFileModuleWithMFConfig
Closed, ResolvedPublic

Description

This custom module is uniquely problematic because it's content-versioned and contains LESS, which means it causes ResourceLoaderFileModule::compileLessFile() to be invoked when building version hashes for the startup module. Sometimes this LESS compilation is in cache, and then there's no performance impact, but when it's not in cache it slows down the startup module quite a bit. I profiled this startup module request yesterday where compileLessFile took 478ms (26.5% of the total).

This module is the only one that both uses content versioning and contains a LESS file, so it must be responsible for all of this time.

One obvious-seeming solution is to convert this module to use packageFiles, so that versioning will be done based on file hashes rather than the module contents. However, the module contains three script files, and all three are built using WebPack. So we'd have to either concatenate these three files into one file as part of the build process, or create a shim file that serves as the entry point and require()s the other files.

Event Timeline

Here's how I determined that mobile.startup (which uses ResourceLoaderFileModuleWithMFConfig) is the only content-versioned module that uses LESS:

catrope@mwdebug1002:~$ mwscript eval.php enwiki
> $rl = MediaWiki\MediaWikiServices::getInstance()->getResourceLoader(); $rlc = ResourceLoaderContext::newDummyContext();

> $moduleNames = $rl->getModuleNames(); $moduleObjects = []; foreach ( $moduleNames as $name ) { $moduleObjects[$name] = $rl->getModule($name); }

> $badModules = array_filter( $moduleObjects, function ( $module ) use ( $rlc ) { if ( !($module instanceof ResourceLoaderFileModule) || !$module->enableModuleContentVersion() ) { return false; } $module->getStyles($rlc); $w = Wikimedia\TestingAccessWrapper::newFromObject($module); return $w->hasGeneratedStyles; } );

> echo count($badModules);
1
> var_dump(array_keys($badModules));
array(1) {
  [0]=>
  string(14) "mobile.startup"
}

Change 524631 had a related patch set uploaded (by Catrope; owner: Catrope):
[mediawiki/extensions/MobileFrontend@master] Hackily convert the mobile.startup module to packageFiles

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

Change 525189 had a related patch set uploaded (by Catrope; owner: Catrope):
[mediawiki/extensions/MobileFrontend@master] ResourceLoaderFileModuleWithMFConfig: Use custom getDefinitionSummary()

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

Change 525189 merged by jenkins-bot:
[mediawiki/extensions/MobileFrontend@master] ResourceLoaderFileModuleWithMFConfig: Use custom getDefinitionSummary()

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

Change 524631 abandoned by Jdlrobson:
Hackily convert the mobile.startup module to packageFiles

Reason:
No longer needed.

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

Jdlrobson claimed this task.