This is a modified rebase of a patch by Tim, see I75f405930a7b14561389c59d147640e870146bec. Some benchmark results (from my laptop): Loading defaults from config-schema.php: - Master: 115/sec ( 8.7ms) - I75f4059: (Tim): 575/sec ( 1.7ms) - Id9dd0bf: (Daniel): 1120/sec ( 0.9ms) - This (Tim+Daniel): 1420/sec ( 0.7ms) Loading defaults and merging settings (worst case): - Master: 80/sec (12.4ms) - I75f4059: (Tim): 93/sec (10.8ms) - Id9dd0bf: (Daniel): 200/sec ( 4.9ms) - This (Tim+Daniel): 682/sec ( 1.5ms) Original commit message by Tim: * Explicitly import function array_key_exists to activate the special opcode * Batch creation of MergeStrategy objects * Batch default assignment to ArrayConfigBuilder The batches mostly help by allowing more inlining, eliminating some function calls. Reduced time for apply/finalize benchmark from 540µs to 170µs. Co-Authored-By: Tim Starling <tstarling@wikimedia.org> Change-Id: I3d4dd685eaaa4351801b3bac6ce1592eea925c5f
58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Settings\Config\ConfigSchemaAggregator;
|
|
use Wikimedia\StaticArrayWriter;
|
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
|
require_once __DIR__ . '/includes/ConfigSchemaDerivativeTrait.php';
|
|
|
|
// Tell Setup.php to load the config schema from MainConfigSchema rather than
|
|
// any generated file, so we can use this script to re-generate a broken schema file.
|
|
define( 'MW_USE_CONFIG_SCHEMA_CLASS', 1 );
|
|
|
|
/**
|
|
* Maintenance script that generates the PHP representation of the config-schema.yaml file.
|
|
*
|
|
* @ingroup Maintenance
|
|
*/
|
|
class GenerateConfigSchemaArray extends Maintenance {
|
|
use ConfigSchemaDerivativeTrait;
|
|
|
|
/** @var string */
|
|
private const DEFAULT_OUTPUT_PATH = __DIR__ . '/../includes/config-schema.php';
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->addDescription( 'Generate an optimized config-schema.php file.' );
|
|
|
|
$this->addOption(
|
|
'output',
|
|
'Path to output relative to $IP. Default: ' . self::DEFAULT_OUTPUT_PATH,
|
|
false,
|
|
true
|
|
);
|
|
}
|
|
|
|
public function execute() {
|
|
$settings = $this->loadSettingsSource();
|
|
$aggregator = new ConfigSchemaAggregator();
|
|
foreach ( $settings['config-schema'] as $key => $schema ) {
|
|
$aggregator->addSchema( $key, $schema );
|
|
}
|
|
$schemaInverse = [
|
|
'default' => $aggregator->getDefaults(),
|
|
'type' => $aggregator->getTypes(),
|
|
'mergeStrategy' => $aggregator->getMergeStrategyNames(),
|
|
];
|
|
$content = ( new StaticArrayWriter() )->write(
|
|
[ 'config-schema-inverse' => $schemaInverse ],
|
|
"This file is automatically generated using maintenance/generateConfigSchemaArray.php.\n" .
|
|
"phpcs:disable Generic.Files.LineLength"
|
|
);
|
|
$this->writeOutput( self::DEFAULT_OUTPUT_PATH, $content );
|
|
}
|
|
}
|
|
|
|
$maintClass = GenerateConfigSchemaArray::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|