Cache condition evaluation results in gclient
Condition evaluation checks are fairly expensive, and turns out we
repeat a lot of checks. All those checks are also done in a single
thread.
With this cache on my workstation, a noop gclient runhooks takes 9.5s.
Without one, it takes 26.2s.
R=gavinmak@google.com
Change-Id: Ie00b7af22cd124d08dd9fd218de77b34bbdfe6ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3309823
Reviewed-by: Gavin Mak <gavinmak@google.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
diff --git a/gclient.py b/gclient.py
index 75a0954..2470c75 100755
--- a/gclient.py
+++ b/gclient.py
@@ -643,6 +643,7 @@
def _deps_to_objects(self, deps, use_relative_paths):
"""Convert a deps dict to a dict of Dependency objects."""
deps_to_add = []
+ cached_conditions = {}
for name, dep_value in deps.items():
should_process = self.should_process
if dep_value is None:
@@ -651,9 +652,12 @@
condition = dep_value.get('condition')
dep_type = dep_value.get('dep_type')
+
if condition and not self._get_option('process_all_deps', False):
- should_process = should_process and gclient_eval.EvaluateCondition(
- condition, self.get_vars())
+ if condition not in cached_conditions:
+ cached_conditions[condition] = gclient_eval.EvaluateCondition(
+ condition, self.get_vars())
+ should_process = should_process and cached_conditions[condition]
# The following option is only set by the 'revinfo' command.
if self._get_option('ignore_dep_type', None) == dep_type: