Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/178450

Change subject: Made SectionProfiler cache the ScopedCallback closure to lower 
overhead
......................................................................

Made SectionProfiler cache the ScopedCallback closure to lower overhead

Change-Id: Ia6f2ef4bb82dad13d49e74c730530295d5719009
---
M includes/libs/ScopedCallback.php
M includes/profiler/SectionProfiler.php
2 files changed, 12 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/50/178450/1

diff --git a/includes/libs/ScopedCallback.php b/includes/libs/ScopedCallback.php
index 631b651..629c269 100644
--- a/includes/libs/ScopedCallback.php
+++ b/includes/libs/ScopedCallback.php
@@ -28,16 +28,20 @@
 class ScopedCallback {
        /** @var callable */
        protected $callback;
+       /** @var array */
+       protected $params;
 
        /**
         * @param callable $callback
+        * @param array $params Callback arguments (since 1.25)
         * @throws Exception
         */
-       public function __construct( $callback ) {
+       public function __construct( $callback, array $params = array() ) {
                if ( !is_callable( $callback ) ) {
                        throw new InvalidArgumentException( "Provided callback 
is not valid." );
                }
                $this->callback = $callback;
+               $this->params = $params;
        }
 
        /**
@@ -67,7 +71,7 @@
         */
        function __destruct() {
                if ( $this->callback !== null ) {
-                       call_user_func( $this->callback );
+                       call_user_func_array( $this->callback, $this->params );
                }
        }
 }
diff --git a/includes/profiler/SectionProfiler.php 
b/includes/profiler/SectionProfiler.php
index 275e986..2c36b68 100644
--- a/includes/profiler/SectionProfiler.php
+++ b/includes/profiler/SectionProfiler.php
@@ -46,6 +46,8 @@
        protected $collateOnly = true;
        /** @var array Cache of a standard broken collation entry */
        protected $errorEntry;
+       /** @var callable Cache of a profile out callback */
+       protected $profileOutCallback;
 
        /**
         * @param array $params
@@ -53,6 +55,9 @@
        public function __construct( array $params = array() ) {
                $this->errorEntry = $this->getErrorEntry();
                $this->collateOnly = empty( $params['trace'] );
+               $this->profileOutCallback = function ( $profiler, $section ) {
+                       $profiler->profileOutInternal( $section );
+               };
        }
 
        /**
@@ -63,9 +68,7 @@
                $this->profileInInternal( $section );
 
                $that = $this;
-               return new ScopedCallback( function () use ( $that, $section ) {
-                       $that->profileOutInternal( $section );
-               } );
+               return new ScopedCallback( $this->profileOutCallback, array( 
$that, $section ) );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/178450
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia6f2ef4bb82dad13d49e74c730530295d5719009
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to