aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
diff options
context:
space:
mode:
authorTimo Tijhof <krinklemail@gmail.com>2021-08-11 19:53:15 +0100
committerCatrope <roan@wikimedia.org>2021-08-19 01:18:32 +0000
commit1367e356e76e75a4fdc3f7a2693ec24cf39c7ba6 (patch)
treea2ace655725756f03344970a2922692c8f2010a9 /tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
parent76245d70ffd5dde20f2a823d8b4fca508b69f393 (diff)
downloadmediawikicore-1367e356e76e75a4fdc3f7a2693ec24cf39c7ba6.tar.gz
mediawikicore-1367e356e76e75a4fdc3f7a2693ec24cf39c7ba6.zip
resourceloader: Remove isFileModule() overhead from web requests
About 1.5% of load.php wall-time is spent in isFileModule() calls during the ServiceWiring/getResourceLoader/register call early on. Reduce the overhead of this cost by moving that logic to the Module class. There are two costs that we save this way: 1. The inherent cost of applying the skinStyles. This is now limited to only the modules that are constructed in a given web request. Thus, apart from the startup response (which constructs all modules), for regular load.php requests and all index.php page views, the vast majority of modules will never need to be constructed, and thus won't pay this cost. 2. The overhead of predicting (and class-loading) for whether a module is (or will become) a FileModule object. This is what isFileModule() does and is the main reason I wrote this patch. It involves class loading, and checks and conditions that run 1000+ times at WMF. This is eliminated now because we no longer have to calculate this decision. Instead, the logic applies when it needs to (due to FileModule implementing it), and doesn't when it doesn't! Change-Id: Ia2db14f930800c96e767b94ef62fb00e9d52725b
Diffstat (limited to 'tests/phpunit/includes/resourceloader/ResourceLoaderTest.php')
-rw-r--r--tests/phpunit/includes/resourceloader/ResourceLoaderTest.php61
1 files changed, 0 insertions, 61 deletions
diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
index a5d88bb8ee79..f3a81ae80249 100644
--- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
+++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php
@@ -150,67 +150,6 @@ class ResourceLoaderTest extends ResourceLoaderTestCase {
);
}
- public function provideTestIsFileModule() {
- $fileModuleObj = $this->createMock( ResourceLoaderFileModule::class );
- return [
- 'factory ignored' => [ false,
- [
- 'factory' => static function () {
- return new ResourceLoaderTestModule();
- }
- ]
- ],
- 'factory ignored (actual FileModule)' => [ false,
- [
- 'factory' => static function () use ( $fileModuleObj ) {
- return $fileModuleObj;
- }
- ]
- ],
- 'simple empty' => [ true,
- []
- ],
- 'simple scripts' => [ true,
- [ 'scripts' => 'example.js' ]
- ],
- 'simple scripts with targets' => [ true, [
- 'scripts' => [ 'a.js', 'b.js' ],
- 'targets' => [ 'desktop', 'mobile' ],
- ] ],
- 'FileModule' => [ true,
- [ 'class' => ResourceLoaderFileModule::class, 'scripts' => 'example.js' ]
- ],
- 'TestModule' => [ false,
- [ 'class' => ResourceLoaderTestModule::class, 'scripts' => 'example.js' ]
- ],
- 'SkinModule (FileModule subclass)' => [ true,
- [ 'class' => ResourceLoaderSkinModule::class, 'scripts' => 'example.js' ]
- ],
- 'WikiModule' => [ false, [
- 'class' => ResourceLoaderWikiModule::class,
- 'scripts' => [ 'MediaWiki:Example.js' ],
- ] ],
- ];
- }
-
- /**
- * @dataProvider provideTestIsFileModule
- * @covers ResourceLoader::isFileModule
- */
- public function testIsFileModule( $expected, $module ) {
- $rl = TestingAccessWrapper::newFromObject( new EmptyResourceLoader() );
- $rl->register( 'test', $module );
- $this->assertSame( $expected, $rl->isFileModule( 'test' ) );
- }
-
- /**
- * @covers ResourceLoader::isFileModule
- */
- public function testIsFileModuleUnknown() {
- $rl = TestingAccessWrapper::newFromObject( new EmptyResourceLoader() );
- $this->assertSame( false, $rl->isFileModule( 'unknown' ) );
- }
-
/**
* @covers ResourceLoader::isModuleRegistered
*/