This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch bschubert/optimize-element-init in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 2f3a5033bfd124a2bf46ed6bc160e219742159c6 Author: Benjamin Schubert <[email protected]> AuthorDate: Thu Oct 10 16:37:01 2019 +0100 _platform/platform.py: Cache result from 'get_host_os' 'get_host_os' is an expensive method and is called twice per element. Caching gives us some performance benefits. --- src/buildstream/_platform/platform.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/buildstream/_platform/platform.py b/src/buildstream/_platform/platform.py index ca5fb75..02e8924 100644 --- a/src/buildstream/_platform/platform.py +++ b/src/buildstream/_platform/platform.py @@ -32,6 +32,7 @@ from .. import utils class Platform(): _host_arch = None # cache to not recompute the host arch every time + _host_os = None # cache not to recompute the host os every time # Platform() # @@ -122,9 +123,11 @@ class Platform(): else: return min(cpu_count, cap) - @staticmethod - def get_host_os(): - return platform.uname().system + @classmethod + def get_host_os(cls): + if cls._host_os is None: + cls._host_os = platform.uname().system + return cls._host_os # canonicalize_arch(): #
