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['config-schema.php'] = [
56 'function' => function () {
57 $settingsBuilder = $this->newSettingsBuilder();
58 $settingsBuilder->load(
59 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
60 );
61 $settingsBuilder->apply();
62 }
63 ];
64
65 $benches['config-schema.php + merge'] = [
66 'function' => function () use ( $defaults ) {
67 $settingsBuilder = $this->newSettingsBuilder();
68
69 // worst case: all config is set before defaults are applied
70 $settingsBuilder->loadArray( [ 'config' => $defaults ] );
71 $settingsBuilder->load(
72 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
73 );
74 $settingsBuilder->apply();
75 }
76 ];
77
78 $benches['MainConfigSchema::class'] = [
79 'function' => function () {
80 $settingsBuilder = $this->newSettingsBuilder();
81 $settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
82 $settingsBuilder->apply();
83 }
84 ];
85
86 $benches['config-schema.php + finalize'] = [
87 'function' => function () {
88 $settingsBuilder = $this->newSettingsBuilder();
89 $settingsBuilder->load(
90 new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
91 );
92 $settingsBuilder->enterRegistrationStage(); // applies some dynamic defaults
93
94 // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.extract
95 extract( $GLOBALS );
96
97 // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgDummyLanguageCodes
99 include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
100 }
101 ];
102
103 $this->bench( $benches );
104 }
105}
106
107// @codeCoverageIgnoreStart
108$maintClass = BenchmarkSettings::class;
109require_once RUN_MAINTENANCE_IF_MAIN;
110// @codeCoverageIgnoreEnd
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.
$wgDummyLanguageCodes
Config variable stub for the DummyLanguageCodes setting, for use by phpdoc and IDEs.