MediaWiki  master
benchmarkSettings.php
Go to the documentation of this file.
1 <?php
30 
31 require_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  include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
128  }
129  ];
130 
131  $benches['config-schema.php + finalize'] = [
132  'function' => function () {
133  $settingsBuilder = $this->newSettingsBuilder();
134  $settingsBuilder->load(
135  new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
136  );
137  $settingsBuilder->finalize(); // applies some dynamic defaults
138 
139  // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.extract
140  extract( $GLOBALS );
141 
142  // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgDummyLanguageCodes
144  include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
145  }
146  ];
147 
148  $this->bench( $benches );
149  }
150 }
151 
152 $maintClass = BenchmarkSettings::class;
153 require_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:90
Maintenance script that benchmarks loading of settings files.
__construct()
Default constructor.
execute()
Do the actual work.
Base class for benchmark scripts.
Definition: Benchmarker.php:40
bench(array $benchs)
Definition: Benchmarker.php:49
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.
Definition: NullIniSink.php:10
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.
$wgDummyLanguageCodes
Config variable stub for the DummyLanguageCodes setting, for use by phpdoc and IDEs.