From: Joshua Spence Date: Tue, 7 Jul 2015 07:56:12 +0000 (+1000) Subject: Linter performance optimization X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bbccf1dd405902b5bd8ddbca55ce0863beb7e927;p=arcanist.git Linter performance optimization 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 --- diff --git a/src/lint/linter/ArcanistXHPASTLinter.php b/src/lint/linter/ArcanistXHPASTLinter.php index 668542f8..3a036f2f 100644 --- a/src/lint/linter/ArcanistXHPASTLinter.php +++ b/src/lint/linter/ArcanistXHPASTLinter.php @@ -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() { diff --git a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php index b98636f6..97e429fb 100644 --- a/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php +++ b/src/lint/linter/xhpast/ArcanistXHPASTLinterRule.php @@ -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();