]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve performance of XHPASTLinter
authorepriestley <git@epriestley.com>
Thu, 8 Mar 2012 20:20:46 +0000 (12:20 -0800)
committerepriestley <git@epriestley.com>
Thu, 8 Mar 2012 20:20:46 +0000 (12:20 -0800)
Summary:
  - XHPASTLinter + coverage is ass-slow.
  - Use caching/perf options introduced by D1828.

Test Plan:
  - Ran profiling for unit tests with new --xprofile command line flag.
  - Old profile: https://secure.phabricator.com/xhprof/profile/PHID-FILE-uiuwsqa5wulj7eyfkjy2/
  - New profile: https://secure.phabricator.com/xhprof/profile/PHID-FILE-nl635t3jcp2sfo2spzwu/
  - Overall runtime decreased from 18.2s to 3.7s (4.9x performance increase) with coverage enabled.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D1829

src/lint/linter/xhpast/ArcanistXHPASTLinter.php

index 0674a058034c7f6d12ee1d87c0b76902668855fa..c24db6e51421a8cbc77238d0f6b0b1930410ede1 100644 (file)
@@ -164,6 +164,9 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
 
     $root = $this->trees[$path]->getRootNode();
 
+    $root->buildSelectCache();
+    $root->buildTokenCache();
+
     $this->lintUseOfThisInStaticMethods($root);
     $this->lintDynamicDefines($root);
     $this->lintSurpriseConstructors($root);
@@ -406,19 +409,18 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
 
 
   protected function lintHashComments($root) {
-    $tokens = $root->getTokens();
-    foreach ($tokens as $token) {
-      if ($token->getTypeName() == 'T_COMMENT') {
-        $value = $token->getValue();
-        if ($value[0] == '#') {
-          $this->raiseLintAtOffset(
-            $token->getOffset(),
-            self::LINT_COMMENT_STYLE,
-            'Use "//" single-line comments, not "#".',
-            '#',
-            '//');
-        }
+    foreach ($root->selectTokensOfType('T_COMMENT') as $comment) {
+      $value = $comment->getValue();
+      if ($value[0] != '#') {
+        continue;
       }
+
+      $this->raiseLintAtOffset(
+        $comment->getOffset(),
+        self::LINT_COMMENT_STYLE,
+        'Use "//" single-line comments, not "#".',
+        '#',
+        '//');
     }
   }
 
@@ -788,13 +790,12 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
         break;
       }
     }
-    foreach ($tokens as $token) {
-      if ($token->getTypeName() == 'T_CLOSE_TAG') {
-        $this->raiseLintAtToken(
-          $token,
-          self::LINT_PHP_CLOSE_TAG,
-          'Do not use the PHP closing tag, "?>".');
-      }
+
+    foreach ($root->selectTokensOfType('T_CLOSE_TAG') as $token) {
+      $this->raiseLintAtToken(
+        $token,
+        self::LINT_PHP_CLOSE_TAG,
+        'Do not use the PHP closing tag, "?>".');
     }
   }
 
@@ -1341,12 +1342,10 @@ final class ArcanistXHPASTLinter extends ArcanistLinter {
   }
 
   protected function lintTODOComments($root) {
-    $tokens = $root->getTokens();
-    foreach ($tokens as $token) {
-      if (!$token->isComment()) {
-        continue;
-      }
+    $comments = $root->selectTokensOfType('T_COMMENT') +
+                $root->selectTokensOfType('T_DOC_COMMENT');
 
+    foreach ($comments as $token) {
       $value = $token->getValue();
       $matches = null;
       $preg = preg_match_all(