MediaWiki master
benchmarkSettings.php
Go to the documentation of this file.
1<?php
10use MediaWiki\MainConfigSchema;
18
19// @codeCoverageIgnoreStart
20require_once __DIR__ . '/../includes/Benchmarker.php';
21// @codeCoverageIgnoreEnd
22
29 public function __construct() {
30 parent::__construct();
31 $this->defaultCount = 100;
32 $this->addDescription( 'Benchmark loading settings files.' );
33 }
34
35 private function newSettingsBuilder(): SettingsBuilder {
36 $extReg = new ExtensionRegistry();
37 $configBuilder = new ArrayConfigBuilder();
38 $phpIniSink = new NullIniSink();
39 return new SettingsBuilder( MW_INSTALL_PATH, $extReg, $configBuilder, $phpIniSink, null );
40 }
41
42 public function execute() {
43 $benches = [];
44
45 $schemaSource = new ReflectionSchemaSource( MainConfigSchema::class );
46 $schema = $schemaSource->load();
47 $defaults = [];
48
49 foreach ( $schema['config-schema'] as $key => $sch ) {
50 if ( array_key_exists( 'default', $sch ) ) {
51 $defaults[$key] = $sch['default'];
52 }
53 }
54
55 $benches['DefaultSettings.php'] = [
56 'setup' => static function () {
57 // do this once beforehand
58 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
59 },
60 'function' => static function () {
61 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
62 }
63 ];
64
65 $benches['config-schema.php'] = [
66 'function' => function () {
67 $settingsBuilder = $this->newSettingsBuilder();
68 $settingsBuilder->load(
69 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
70 );
71 $settingsBuilder->apply();
72 }
73 ];
74
75 $benches['config-schema.php + merge'] = [
76 'function' => function () use ( $defaults ) {
77 $settingsBuilder = $this->newSettingsBuilder();
78
79 // worst case: all config is set before defaults are applied
80 $settingsBuilder->loadArray( [ 'config' => $defaults ] );
81 $settingsBuilder->load(
82 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
83 );
84 $settingsBuilder->apply();
85 }
86 ];
87
88 $benches['MainConfigSchema::class'] = [
89 'function' => function () {
90 $settingsBuilder = $this->newSettingsBuilder();
91 $settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
92 $settingsBuilder->apply();
93 }
94 ];
95
96 $benches['DefaultSettings.php + SetupDynamicConfig.php'] = [
97 'function' => static function () {
98 $IP = MW_INSTALL_PATH;
99 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
100
101 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgLocaltimezone
102 $wgLocaltimezone = 'utc';
103 include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
104 }
105 ];
106
107 $benches['config-schema.php + finalize'] = [
108 'function' => function () {
109 $settingsBuilder = $this->newSettingsBuilder();
110 $settingsBuilder->load(
111 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
112 );
113 $settingsBuilder->enterRegistrationStage(); // applies some dynamic defaults
114
115 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.extract
116 extract( $GLOBALS );
117
118 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgDummyLanguageCodes
120 include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
121 }
122 ];
123
124 $this->bench( $benches );
125 }
126}
127
128// @codeCoverageIgnoreStart
129$maintClass = BenchmarkSettings::class;
130require_once RUN_MAINTENANCE_IF_MAIN;
131// @codeCoverageIgnoreEnd
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:90
Maintenance script that benchmarks loading of settings files.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
addDescription( $text)
Set the description text.
Load JSON files, and uses a Processor to extract information.
Null implementation of PhpIniSink, useful for testing and benchmarking.
Builder class for constructing a Config object from a set of sources during bootstrap.
Settings loaded from a PHP file path as an array structure.
Constructs a settings array based on a PHP class by inspecting class members to construct a schema.
$wgLocaltimezone
Config variable stub for the Localtimezone setting, for use by phpdoc and IDEs.
$wgDummyLanguageCodes
Config variable stub for the DummyLanguageCodes setting, for use by phpdoc and IDEs.