]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Performance improvements for linting in an HG repo.
authorkeegancsmith <keegancsmith@fb.com>
Wed, 7 Nov 2012 03:30:08 +0000 (19:30 -0800)
committerepriestley <git@epriestley.com>
Wed, 7 Nov 2012 18:24:28 +0000 (10:24 -0800)
Summary:
Run `hg status` as a Future while getting the diff. Add a cache for
getRawDiffText().

Test Plan:
Run `arc lint --trace` on a HG repo and confirm that `diff` is only called once
and `status` is run in the background.

Reviewers: epriestley

Reviewed By: epriestley

CC: yliang, dpepper, aran, Korvin
Maniphest Tasks: T2016

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

src/repository/api/ArcanistMercurialAPI.php

index dd890d825c072370100cde42097af5d7e1599126..83d94d4dd4bee5161847a47c28ccd415d49cde73 100644 (file)
@@ -14,6 +14,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
   private $workingCopyRevision;
   private $localCommitInfo;
   private $includeDirectoryStateInDiffs;
+  private $rawDiffCache = array();
 
   protected function buildLocalFuture(array $argv) {
 
@@ -278,6 +279,10 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
       // there is no way to get file change status across multiple commits, so
       // just take the entire diff and parse it to figure out what's changed.
 
+      // Execute status in the background
+      $status_future = $this->buildLocalFuture(array('status'));
+      $status_future->start();
+
       $diff = $this->getFullMercurialDiff();
 
       if (!$diff) {
@@ -311,7 +316,7 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
         $status_map[$change->getCurrentPath()] = $flags;
       }
 
-      list($stdout) = $this->execxLocal('status');
+      list($stdout) = $status_future->resolvex();
 
       $working_status = ArcanistMercurialParser::parseMercurialStatus($stdout);
       foreach ($working_status as $path => $status) {
@@ -354,12 +359,19 @@ final class ArcanistMercurialAPI extends ArcanistRepositoryAPI {
       $range .= '...';
     }
 
+    $raw_diff_cache_key = $options.' '.$range.' '.$path;
+    if (idx($this->rawDiffCache, $raw_diff_cache_key)) {
+      return idx($this->rawDiffCache, $raw_diff_cache_key);
+    }
+
     list($stdout) = $this->execxLocal(
       'diff %C --rev %s -- %s',
       $options,
       $range,
       $path);
 
+    $this->rawDiffCache[$raw_diff_cache_key] = $stdout;
+
     return $stdout;
   }