info: Parallelize project data gathering for JSON output

https://gerrit-review.googlesource.com/c/git-repo/+/581921 parallelized
`repo info` for text output. This commit does the same for JSON output
format.

Benchmarked `repo info --format=json` on an Android workspace with ~3k
projects (N=3):
- Before (sequential): 1m 30s average
- After (parallelized): 46s average (~2x speedup)

Verified that the JSON output is identical before and after.

Bug: 526685287
Change-Id: If573223aba584f8b932f87d29e34ed565c5c930a
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/601861
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Brian Gan <brgan@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
This commit is contained in:
Gavin Mak
2026-06-29 10:42:01 -07:00
committed by gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent a27dbcdb7b
commit 91986011b0
2 changed files with 54 additions and 2 deletions
+24 -2
View File
@@ -191,7 +191,8 @@ class Info(PagedCommand):
"superproject_revision": srev,
}
def _getProjectData(self, project) -> Dict[str, Any]:
@classmethod
def _getProjectData(cls, project) -> Dict[str, Any]:
"""Gather project data as a dict."""
data = {
"name": project.name,
@@ -206,6 +207,12 @@ class Info(PagedCommand):
data["current_branch"] = currentBranch
return data
@classmethod
def _ProjectDataHelper(cls, project_idx: int) -> Dict[str, Any]:
"""Helper to get project data in parallel."""
project = cls.get_parallel_context()["projects"][project_idx]
return cls._getProjectData(project)
def _ExecuteJson(self, opt, args) -> None:
"""Output info as JSON."""
result = {}
@@ -215,7 +222,22 @@ class Info(PagedCommand):
projs = self.GetProjects(
args, all_manifests=not opt.this_manifest_only
)
result["projects"] = [self._getProjectData(p) for p in projs]
project_data = []
def _ProcessResults(_pool, _output, results):
project_data.extend(results)
with self.ParallelContext():
self.get_parallel_context()["projects"] = projs
self.ExecuteInParallel(
opt.jobs,
self._ProjectDataHelper,
range(len(projs)),
callback=_ProcessResults,
ordered=True,
chunksize=1,
)
result["projects"] = project_data
json_settings = {
# JSON style guide says Unicode characters are fully allowed.