]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Parallelize calls for ArcanistGitAPI::getWorkingCopyStatus
authorYiding Jia <yidingjia@fb.com>
Tue, 5 Jul 2011 18:06:46 +0000 (11:06 -0700)
committerYiding Jia <yidingjia@fb.com>
Wed, 6 Jul 2011 17:34:51 +0000 (10:34 -0700)
Summary:
executes the calls to git in parallel to improve startup performance of
arc lint and possibly other commands

Gets about a 2~3x speedup when repo is in buffer cache, with 4 cores.

Test Plan:
arc linted a repo with unstaged, untracked, staged, and committed
changes, see that the same files were linted.

Reviewed By: jungejason
Reviewers: jungejason, epriestley
Commenters: epriestley
CC: aran, jungejason, epriestley
Differential Revision: 594

src/repository/api/git/ArcanistGitAPI.php
src/repository/api/git/__init__.php

index e69f77853aa5da84c96eba9f14abb9dd0824a468..13570a464c88a29f95eb6b0cce16d2a2717416f4 100644 (file)
@@ -183,17 +183,47 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
 
       $options = $this->getDiffBaseOptions();
 
+      // -- parallelize these slow cpu bound git calls.
+
       // Find committed changes.
-      list($stdout) = execx(
+      $committed_future = new ExecFuture(
         "(cd %s; git diff {$options} --raw %s --)",
         $this->getPath(),
         $this->getRelativeCommit());
-      $files = $this->parseGitStatus($stdout);
 
       // Find uncommitted changes.
-      list($stdout) = execx(
+      $uncommitted_future = new ExecFuture(
         "(cd %s; git diff {$options} --raw HEAD --)",
         $this->getPath());
+
+      // Untracked files
+      $untracked_future = new ExecFuture(
+        '(cd %s; git ls-files --others --exclude-standard)',
+        $this->getPath());
+
+      // TODO: This doesn't list unstaged adds. It's not clear how to get that
+      // list other than "git status --porcelain" and then parsing it. :/
+
+      // Unstaged changes
+      $unstaged_future = new ExecFuture(
+        '(cd %s; git ls-files -m)',
+        $this->getPath());
+
+      $futures = array(
+        $committed_future,
+        $uncommitted_future,
+        $untracked_future,
+        $unstaged_future
+      );
+      Futures($futures)->resolveAll();
+
+
+      // -- read back and process the results
+
+      list($stdout, $stderr) = $committed_future->resolvex();
+      $files = $this->parseGitStatus($stdout);
+
+      list($stdout, $stderr) = $uncommitted_future->resolvex();
       $uncommitted_files = $this->parseGitStatus($stdout);
       foreach ($uncommitted_files as $path => $mask) {
         $mask |= self::FLAG_UNCOMMITTED;
@@ -203,10 +233,7 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
         $files[$path] |= $mask;
       }
 
-      // Find untracked files.
-      list($stdout) = execx(
-        '(cd %s; git ls-files --others --exclude-standard)',
-        $this->getPath());
+      list($stdout, $stderr) = $untracked_future->resolvex();
       $stdout = rtrim($stdout, "\n");
       if (strlen($stdout)) {
         $stdout = explode("\n", $stdout);
@@ -215,13 +242,7 @@ class ArcanistGitAPI extends ArcanistRepositoryAPI {
         }
       }
 
-      // TODO: This doesn't list unstaged adds. It's not clear how to get that
-      // list other than "git status --porcelain" and then parsing it. :/
-
-      // Find unstaged changes.
-      list($stdout) = execx(
-        '(cd %s; git ls-files -m)',
-        $this->getPath());
+      list($stdout, $stderr) = $unstaged_future->resolvex();
       $stdout = rtrim($stdout, "\n");
       if (strlen($stdout)) {
         $stdout = explode("\n", $stdout);
index 6f6dae563a3749a2ad3e168fb89da880d6cb6452..c225acc7c3025f45badaf33749c5174f8e5c646b 100644 (file)
@@ -8,6 +8,7 @@
 
 phutil_require_module('arcanist', 'repository/api/base');
 
+phutil_require_module('phutil', 'future');
 phutil_require_module('phutil', 'future/exec');
 phutil_require_module('phutil', 'utils');