MediaWiki master
benchmarkSettings.php
Go to the documentation of this file.
1<?php
31
32// @codeCoverageIgnoreStart
33require_once __DIR__ . '/../includes/Benchmarker.php';
34// @codeCoverageIgnoreEnd
35
41class BenchmarkSettings extends Benchmarker {
42 public function __construct() {
43 parent::__construct();
44 $this->defaultCount = 100;
45 $this->addDescription( 'Benchmark loading settings files.' );
46 }
47
48 private function newSettingsBuilder() {
49 $extReg = new ExtensionRegistry();
50 $configBuilder = new ArrayConfigBuilder();
51 $phpIniSink = new NullIniSink();
52 return new SettingsBuilder( MW_INSTALL_PATH, $extReg, $configBuilder, $phpIniSink, null );
53 }
54
55 public function execute() {
56 $benches = [];
57
58 $schemaSource = new ReflectionSchemaSource( MainConfigSchema::class );
59 $schema = $schemaSource->load();
60 $defaults = [];
61
62 foreach ( $schema['config-schema'] as $key => $sch ) {
63 if ( array_key_exists( 'default', $sch ) ) {
64 $defaults[$key] = $sch['default'];
65 }
66 }
67
68 $benches['DefaultSettings.php'] = [
69 'setup' => static function () {
70 // do this once beforehand
71 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
72 },
73 'function' => static function () {
74 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
75 }
76 ];
77
78 $benches['config-schema.php'] = [
79 'function' => function () {
80 $settingsBuilder = $this->newSettingsBuilder();
81 $settingsBuilder->load(
82 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
83 );
84 $settingsBuilder->apply();
85 }
86 ];
87
88 $benches['config-schema.php + merge'] = [
89 'function' => function () use ( $defaults ) {
90 $settingsBuilder = $this->newSettingsBuilder();
91
92 // worst case: all config is set before defaults are applied
93 $settingsBuilder->loadArray( [ 'config' => $defaults ] );
94 $settingsBuilder->load(
95 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
96 );
97 $settingsBuilder->apply();
98 }
99 ];
100
101 $benches['MainConfigSchema::class'] = [
102 'function' => function () {
103 $settingsBuilder = $this->newSettingsBuilder();
104 $settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
105 $settingsBuilder->apply();
106 }
107 ];
108
109 $benches['DefaultSettings.php + SetupDynamicConfig.php'] = [
110 'function' => static function () {
111 $IP = MW_INSTALL_PATH;
112 include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
113
114 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgLocaltimezone
115 $wgLocaltimezone = 'utc';
116 include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
117 }
118 ];
119
120 $benches['config-schema.php + finalize'] = [
121 'function' => function () {
122 $settingsBuilder = $this->newSettingsBuilder();
123 $settingsBuilder->load(
124 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
125 );
126 $settingsBuilder->enterRegistrationStage(); // applies some dynamic defaults
127
128 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.extract
129 extract( $GLOBALS );
130
131 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgDummyLanguageCodes
133 include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
134 }
135 ];
136
137 $this->bench( $benches );
138 }
139}
140
141// @codeCoverageIgnoreStart
142$maintClass = BenchmarkSettings::class;
143require_once RUN_MAINTENANCE_IF_MAIN;
144// @codeCoverageIgnoreEnd
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:105
Maintenance script that benchmarks loading of settings files.
This class contains schema declarations for all configuration variables known to MediaWiki core.
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.