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['config-schema.php'] = [
76  'function' => function () {
77  $settingsBuilder = $this->newSettingsBuilder();
78  $settingsBuilder->load(
79  new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
80  );
81  $settingsBuilder->apply();
82  }
83  ];
84 
85  $benches['config-schema.php + merge'] = [
86  'function' => function () use ( $defaults ) {
87  $settingsBuilder = $this->newSettingsBuilder();
88 
89  // worst case: all config is set before defaults are applied
90  $settingsBuilder->loadArray( [ 'config' => $defaults ] );
91  $settingsBuilder->load(
92  new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
93  );
94  $settingsBuilder->apply();
95  }
96  ];
97 
98  $benches['MainConfigSchema::class'] = [
99  'function' => function () {
100  $settingsBuilder = $this->newSettingsBuilder();
101  $settingsBuilder->load( new ReflectionSchemaSource( MainConfigSchema::class ) );
102  $settingsBuilder->apply();
103  }
104  ];
105 
106  $benches['DefaultSettings.php + SetupDynamicConfig.php'] = [
107  'function' => static function () {
108  $IP = MW_INSTALL_PATH;
109  include MW_INSTALL_PATH . '/includes/DefaultSettings.php';
110 
111  // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgLocaltimezone
112  $wgLocaltimezone = 'utc';
113  include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
114  }
115  ];
116 
117  $benches['config-schema.php + finalize'] = [
118  'function' => function () {
119  $settingsBuilder = $this->newSettingsBuilder();
120  $settingsBuilder->load(
121  new PhpSettingsSource( MW_INSTALL_PATH . '/includes/config-schema.php' )
122  );
123  $settingsBuilder->enterRegistrationStage(); // applies some dynamic defaults
124 
125  // phpcs:ignore MediaWiki.Usage.ForbiddenFunctions.extract
126  extract( $GLOBALS );
127 
128  // phpcs:ignore MediaWiki.VariableAnalysis.MisleadingGlobalNames.Misleading$wgDummyLanguageCodes
130  include MW_INSTALL_PATH . '/includes/SetupDynamicConfig.php';
131  }
132  ];
133 
134  $this->bench( $benches );
135  }
136 }
137 
138 $maintClass = BenchmarkSettings::class;
139 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:96
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
Load JSON files, and uses a Processor to extract information.
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
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.