Made a new SectionProfileCallback class that extends ScopedCallback

* This is now used by SectionProfiler and avoids the high overhead of call_user_func_array().

Change-Id: I7ff2c9a35c7cd8ee462f2368b655e766ad33dd63
This commit is contained in:
Aaron Schulz 2014-12-17 13:16:06 -08:00
parent 2ce435465a
commit 626aede99b
4 changed files with 31 additions and 7 deletions

View file

@ -1018,6 +1018,7 @@ $wgAutoloadLocalClasses = array(
'SearchResultSet' => __DIR__ . '/includes/search/SearchResultSet.php',
'SearchSqlite' => __DIR__ . '/includes/search/SearchSqlite.php',
'SearchUpdate' => __DIR__ . '/includes/deferred/SearchUpdate.php',
'SectionProfileCallback' => __DIR__ . '/includes/profiler/SectionProfiler.php',
'SectionProfiler' => __DIR__ . '/includes/profiler/SectionProfiler.php',
'SevenZipStream' => __DIR__ . '/maintenance/7zip.inc',
'ShiConverter' => __DIR__ . '/languages/classes/LanguageShi.php',

View file

@ -32,12 +32,12 @@ class ScopedCallback {
protected $params;
/**
* @param callable $callback
* @param callable|null $callback
* @param array $params Callback arguments (since 1.25)
* @throws Exception
*/
public function __construct( $callback, array $params = array() ) {
if ( !is_callable( $callback ) ) {
if ( $callback !== null && !is_callable( $callback ) ) {
throw new InvalidArgumentException( "Provided callback is not valid." );
}
$this->callback = $callback;

View file

@ -34,9 +34,7 @@ class ProfilerStub extends Profiler {
}
public function scopedProfileIn( $section ) {
return new ScopedCallback( function () {
// no-op
} );
return new ScopedCallback( null ); // no-op
}
public function getFunctionStats() {

View file

@ -67,8 +67,7 @@ class SectionProfiler {
public function scopedProfileIn( $section ) {
$this->profileInInternal( $section );
$that = $this;
return new ScopedCallback( $this->profileOutCallback, array( $that, $section ) );
return new SectionProfileCallback( $this, $section );
}
/**
@ -502,3 +501,29 @@ class SectionProfiler {
}
}
}
/**
* Subclass ScopedCallback to avoid call_user_func_array(), which is slow
*
* This class should not be used outside of SectionProfiler
*/
class SectionProfileCallback extends ScopedCallback {
/** @var SectionProfiler */
protected $profiler;
/** @var string */
protected $section;
/**
* @param SectionProfiler $profiler
* @param string $section
*/
public function __construct( SectionProfiler $profiler, $section ) {
parent::__construct( null );
$this->profiler = $profiler;
$this->section = $section;
}
function __destruct() {
$this->profiler->profileOutInternal( $this->section );
}
}