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