]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Linter performance optimization
authorJoshua Spence <josh@joshuaspence.com>
Tue, 7 Jul 2015 07:56:12 +0000 (17:56 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Tue, 7 Jul 2015 08:00:27 +0000 (18:00 +1000)
Summary: Optimize `ArcanistXHPASTLinterRule::getLintID`.

Test Plan: Compare [[https://secure.phabricator.com/xhprof/profile/PHID-FILE-wwgi4xzupt4z2fvbyff3/?symbol=mpull | before]] and [[https://secure.phabricator.com/xhprof/profile/PHID-FILE-rn2ialomtr2apnkzisb3/?symbol=mpull | after]].

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13541

src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php

index 668542f842e6f15d879807d5c0ac1d50b24104c6..3a036f2f90628ec78e528491b2ce53c098776f3f 100644 (file)
@@ -7,6 +7,9 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
 
   private $rules = array();
 
+  private $lintNameMap;
+  private $lintSeverityMap;
+
   public function __construct() {
     $this->rules = ArcanistXHPASTLinterRule::loadAllRules();
   }
@@ -37,11 +40,25 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
   }
 
   public function getLintNameMap() {
-    return mpull($this->rules, 'getLintName', 'getLintID');
+    if ($this->lintNameMap === null) {
+      $this->lintNameMap = mpull(
+        $this->rules,
+        'getLintName',
+        'getLintID');
+    }
+
+    return $this->lintNameMap;
   }
 
   public function getLintSeverityMap() {
-    return mpull($this->rules, 'getLintSeverity', 'getLintID');
+    if ($this->lintSeverityMap === null) {
+      $this->lintSeverityMap = mpull(
+        $this->rules,
+        'getLintSeverity',
+        'getLintID');
+    }
+
+    return $this->lintSeverityMap;
   }
 
   public function getLinterConfigurationOptions() {
index b98636f651f1d2f44fec18aa3080bb67af68d2b4..97e429fb238790207b7b1736f581ec705f5ea891 100644 (file)
@@ -3,6 +3,7 @@
 abstract class ArcanistXHPASTLinterRule extends Phobject {
 
   private $linter = null;
+  private $lintID = null;
 
   final public static function loadAllRules() {
     $rules = array();
@@ -31,26 +32,31 @@ abstract class ArcanistXHPASTLinterRule extends Phobject {
   }
 
   final public function getLintID() {
-    $class = new ReflectionClass($this);
-
-    $const = $class->getConstant('ID');
-    if ($const === false) {
-      throw new Exception(
-        pht(
-          '`%s` class `%s` must define an ID constant.',
-          __CLASS__,
-          get_class($this)));
-    }
+    if ($this->lintID === null) {
+      $class = new ReflectionClass($this);
+
+      $const = $class->getConstant('ID');
+      if ($const === false) {
+        throw new Exception(
+          pht(
+            '`%s` class `%s` must define an ID constant.',
+            __CLASS__,
+            get_class($this)));
+      }
+
+      if (!is_int($const)) {
+        throw new Exception(
+          pht(
+            '`%s` class `%s` has an invalid ID constant. '.
+            'ID must be an integer.',
+            __CLASS__,
+            get_class($this)));
+      }
 
-    if (!is_int($const)) {
-      throw new Exception(
-        pht(
-          '`%s` class `%s` has an invalid ID constant. ID must be an integer.',
-          __CLASS__,
-          get_class($this)));
+      $this->lintID = $const;
     }
 
-    return $const;
+    return $this->lintID;
   }
 
   abstract public function getLintName();