From 9cbe9a07ecdb02978f2fcb8aaed03bbb69e23185 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Wed, 1 Dec 2021 17:25:16 +0000 Subject: [PATCH] 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 Reviewed-by: Dirk Pranke Commit-Queue: Josip Sokcevic --- gclient.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gclient.py b/gclient.py index 75a0954c6..2470c7560 100755 --- a/gclient.py +++ b/gclient.py @@ -643,6 +643,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): 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 @@ class Dependency(gclient_utils.WorkItem, DependencySettings): 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: