summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2019-02-12 13:07:14 +0000
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2019-02-12 14:29:25 +0000
commita149a0d0565d8357b3baf41359fa3c7a02630325 (patch)
tree4bb7e8620187438b85d9826c59d8f1d89c2f6aa1
parent7c86ea0d29ddf0331ebc4e8a52ead8e3140e73ab (diff)
downloadbuildstream-danielsilverstone-ct/further-optimisations.tar.gz
_context.py: Cache result of get_strict()danielsilverstone-ct/further-optimisations
While get_strict() doesn't look expensive per-se, it is called so many times that it is valuable to cache the result once computed. Since I don't think it can change once it is computable, cache it immediately that becomes possible and we save 20s in my test case. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r--buildstream/_context.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 1d049f7a6..9c53e7d75 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -361,14 +361,17 @@ class Context():
# (bool): Whether or not to use strict build plan
#
def get_strict(self):
+ if self._strict_build_plan is None:
+ # Either we're not overridden or we've never worked it out before
+ # so work out if we should be strict, and then cache the result
+ toplevel = self.get_toplevel_project()
+ overrides = self.get_overrides(toplevel.name)
+ self._strict_build_plan = _yaml.node_get(overrides, bool, 'strict', default_value=True)
# If it was set by the CLI, it overrides any config
- if self._strict_build_plan is not None:
- return self._strict_build_plan
-
- toplevel = self.get_toplevel_project()
- overrides = self.get_overrides(toplevel.name)
- return _yaml.node_get(overrides, bool, 'strict', default_value=True)
+ # Ditto if we've already computed this, then we return the computed
+ # value which we cache here too.
+ return self._strict_build_plan
# get_cache_key():
#