diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-02-12 13:07:14 +0000 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-02-12 15:12:30 +0000 |
commit | 0928e570ebb1289a6d418a6df71c98b923fb1b4e (patch) | |
tree | cf5b1290564f739e242af1037a598ceca246d3ca /buildstream/_context.py | |
parent | 69ee11c61b98d3bee3c2449c58a4673830027865 (diff) | |
download | buildstream-0928e570ebb1289a6d418a6df71c98b923fb1b4e.tar.gz |
_context.py: Cache result of get_strict()
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>
Diffstat (limited to 'buildstream/_context.py')
-rw-r--r-- | buildstream/_context.py | 15 |
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(): # |