diff options
author | Kuang-che Wu <kcwu@google.com> | 2024-10-22 21:04:41 +0800 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-10-23 23:34:34 +0000 |
commit | 8da4861b3860c505e39341b4135c21f67569e4d8 (patch) | |
tree | 6f300266c91322df0e61953b84381e1f403074a5 /subcmds/checkout.py | |
parent | 39ffd9977e2f6cb1ca1757e59173fc93e0eab72c (diff) | |
download | git-repo-8da4861b3860c505e39341b4135c21f67569e4d8.tar.gz |
subcmds: reduce multiprocessing serialization overhead
Follow the same approach as 39ffd9977e to reduce serialization overhead.
Below benchmarks are tested with 2.7k projects on my workstation
(warm cache). git tracing is disabled for benchmark.
(seconds) | v2.48 | v2.48 | this CL | this CL
| | -j32 | | -j32
-----------------------------------------------------------
with clean tree state:
branches (none) | 5.6 | 5.9 | 1.0 | 0.9
status (clean) | 21.3 | 9.4 | 19.4 | 4.7
diff (none) | 7.6 | 7.2 | 5.7 | 2.2
prune (none) | 5.7 | 6.1 | 1.3 | 1.2
abandon (none) | 19.4 | 18.6 | 0.9 | 0.8
upload (none) | 19.7 | 18.7 | 0.9 | 0.8
forall -c true | 7.5 | 7.6 | 0.6 | 0.6
forall -c "git log -1" | 11.3 | 11.1 | 0.6 | 0.6
with branches:
start BRANCH --all | 21.9 | 20.3 | 13.6 | 2.6
checkout BRANCH | 29.1 | 27.8 | 1.1 | 1.0
branches (2) | 28.0 | 28.6 | 1.5 | 1.3
abandon BRANCH | 29.2 | 27.5 | 9.7 | 2.2
Bug: b/371638995
Change-Id: I53989a3d1e43063587b3f52f852b1c2c56b49412
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/440221
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Tested-by: Kuang-che Wu <kcwu@google.com>
Commit-Queue: Kuang-che Wu <kcwu@google.com>
Diffstat (limited to 'subcmds/checkout.py')
-rw-r--r-- | subcmds/checkout.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/subcmds/checkout.py b/subcmds/checkout.py index 379bfa18..859ddf6c 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py | |||
@@ -20,7 +20,6 @@ from command import DEFAULT_LOCAL_JOBS | |||
20 | from error import GitError | 20 | from error import GitError |
21 | from error import RepoExitError | 21 | from error import RepoExitError |
22 | from progress import Progress | 22 | from progress import Progress |
23 | from project import Project | ||
24 | from repo_logging import RepoLogger | 23 | from repo_logging import RepoLogger |
25 | 24 | ||
26 | 25 | ||
@@ -30,7 +29,7 @@ logger = RepoLogger(__file__) | |||
30 | class CheckoutBranchResult(NamedTuple): | 29 | class CheckoutBranchResult(NamedTuple): |
31 | # Whether the Project is on the branch (i.e. branch exists and no errors) | 30 | # Whether the Project is on the branch (i.e. branch exists and no errors) |
32 | result: bool | 31 | result: bool |
33 | project: Project | 32 | project_idx: int |
34 | error: Exception | 33 | error: Exception |
35 | 34 | ||
36 | 35 | ||
@@ -62,15 +61,17 @@ The command is equivalent to: | |||
62 | if not args: | 61 | if not args: |
63 | self.Usage() | 62 | self.Usage() |
64 | 63 | ||
65 | def _ExecuteOne(self, nb, project): | 64 | @classmethod |
65 | def _ExecuteOne(cls, nb, project_idx): | ||
66 | """Checkout one project.""" | 66 | """Checkout one project.""" |
67 | error = None | 67 | error = None |
68 | result = None | 68 | result = None |
69 | project = cls.get_parallel_context()["projects"][project_idx] | ||
69 | try: | 70 | try: |
70 | result = project.CheckoutBranch(nb) | 71 | result = project.CheckoutBranch(nb) |
71 | except GitError as e: | 72 | except GitError as e: |
72 | error = e | 73 | error = e |
73 | return CheckoutBranchResult(result, project, error) | 74 | return CheckoutBranchResult(result, project_idx, error) |
74 | 75 | ||
75 | def Execute(self, opt, args): | 76 | def Execute(self, opt, args): |
76 | nb = args[0] | 77 | nb = args[0] |
@@ -83,22 +84,25 @@ The command is equivalent to: | |||
83 | 84 | ||
84 | def _ProcessResults(_pool, pm, results): | 85 | def _ProcessResults(_pool, pm, results): |
85 | for result in results: | 86 | for result in results: |
87 | project = all_projects[result.project_idx] | ||
86 | if result.error is not None: | 88 | if result.error is not None: |
87 | err.append(result.error) | 89 | err.append(result.error) |
88 | err_projects.append(result.project) | 90 | err_projects.append(project) |
89 | elif result.result: | 91 | elif result.result: |
90 | success.append(result.project) | 92 | success.append(project) |
91 | pm.update(msg="") | 93 | pm.update(msg="") |
92 | 94 | ||
93 | self.ExecuteInParallel( | 95 | with self.ParallelContext(): |
94 | opt.jobs, | 96 | self.get_parallel_context()["projects"] = all_projects |
95 | functools.partial(self._ExecuteOne, nb), | 97 | self.ExecuteInParallel( |
96 | all_projects, | 98 | opt.jobs, |
97 | callback=_ProcessResults, | 99 | functools.partial(self._ExecuteOne, nb), |
98 | output=Progress( | 100 | range(len(all_projects)), |
99 | f"Checkout {nb}", len(all_projects), quiet=opt.quiet | 101 | callback=_ProcessResults, |
100 | ), | 102 | output=Progress( |
101 | ) | 103 | f"Checkout {nb}", len(all_projects), quiet=opt.quiet |
104 | ), | ||
105 | ) | ||
102 | 106 | ||
103 | if err_projects: | 107 | if err_projects: |
104 | for p in err_projects: | 108 | for p in err_projects: |