From 0efe030cd9473ddd6b1baa63b4cb72e80a4380f1 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 14 Sep 2016 23:55:35 -0700 Subject: [PATCH] benchmarkParse: Add option to clear link cache For performance testing the lookup of links (e.g. LinkHolderArray), allow resetting the LinkCache after every parse. Change-Id: I75c2cad9a8cf1b41d192708773194f799673ce83 --- maintenance/benchmarks/benchmarkParse.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/maintenance/benchmarks/benchmarkParse.php b/maintenance/benchmarks/benchmarkParse.php index 884e307f68..1753250bcd 100644 --- a/maintenance/benchmarks/benchmarkParse.php +++ b/maintenance/benchmarks/benchmarkParse.php @@ -24,6 +24,8 @@ require __DIR__ . '/../Maintenance.php'; +use MediaWiki\MediaWikiServices; + /** * Maintenance script to benchmark how long it takes to parse a given title at an optionally * specified timestamp @@ -34,6 +36,13 @@ class BenchmarkParse extends Maintenance { /** @var string MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS) */ private $templateTimestamp = null; + private $clearLinkCache = false; + + /** + * @var LinkCache + */ + private $linkCache; + /** @var array Cache that maps a Title DB key to revision ID for the requested timestamp */ private $idCache = []; @@ -52,6 +61,8 @@ class BenchmarkParse extends Maintenance { 'Use templates which were current at the given time (except that moves and ' . 'deletes are not handled properly)', false, true ); + $this->addOption( 'reset-linkcache', 'Reset the LinkCache after every parse.', + false, false ); } function execute() { @@ -60,6 +71,10 @@ class BenchmarkParse extends Maintenance { Hooks::register( 'BeforeParserFetchTemplateAndtitle', [ $this, 'onFetchTemplate' ] ); } + $this->clearLinkCache = $this->hasOption( 'reset-linkcache' ); + // Set as a member variable to avoid function calls when we're timing the parse + $this->linkCache = MediaWikiServices::getInstance()->getLinkCache(); + $title = Title::newFromText( $this->getArg() ); if ( !$title ) { $this->error( "Invalid title" ); @@ -144,6 +159,9 @@ class BenchmarkParse extends Maintenance { function runParser( Revision $revision ) { $content = $revision->getContent(); $content->getParserOutput( $revision->getTitle(), $revision->getId() ); + if ( $this->clearLinkCache ) { + $this->linkCache->clear(); + } } /** -- 2.20.1