summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-16 16:56:55 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-23 23:17:58 -0800
commit48befd67b565efcb218849644c9dc1f728e2f095 (patch)
treede1aa5bcec9b6e9741a52c66a04f6ea5101e165f /lib
parent37eac1a2269fcaf1bd0e1fa51851150874676e1a (diff)
downloadspack-48befd67b565efcb218849644c9dc1f728e2f095.tar.gz
spack-48befd67b565efcb218849644c9dc1f728e2f095.tar.bz2
spack-48befd67b565efcb218849644c9dc1f728e2f095.tar.xz
spack-48befd67b565efcb218849644c9dc1f728e2f095.zip
performance: memoize spack.architecture.get_platform()
`get_platform()` is pretty expensive and can be called many times in a spack invocation. - [x] memoize `get_platform()`
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/architecture.py1
-rw-r--r--lib/spack/spack/test/concretize.py7
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/spack/spack/architecture.py b/lib/spack/spack/architecture.py
index 0e318bbccf..7552795cd2 100644
--- a/lib/spack/spack/architecture.py
+++ b/lib/spack/spack/architecture.py
@@ -436,6 +436,7 @@ class Arch(object):
return arch_for_spec(spec)
+@memoized
def get_platform(platform_name):
"""Returns a platform object that corresponds to the given name."""
platform_list = all_platforms()
diff --git a/lib/spack/spack/test/concretize.py b/lib/spack/spack/test/concretize.py
index e0774909f4..4b17e755ed 100644
--- a/lib/spack/spack/test/concretize.py
+++ b/lib/spack/spack/test/concretize.py
@@ -94,6 +94,10 @@ def current_host(request, monkeypatch):
# preferred target via packages.yaml
cpu, _, is_preference = request.param.partition('-')
target = llnl.util.cpu.targets[cpu]
+
+ # this function is memoized, so clear its state for testing
+ spack.architecture.get_platform.cache.clear()
+
if not is_preference:
monkeypatch.setattr(llnl.util.cpu, 'host', lambda: target)
monkeypatch.setattr(spack.platforms.test.Test, 'default', cpu)
@@ -104,6 +108,9 @@ def current_host(request, monkeypatch):
with spack.config.override('packages:all', {'target': [cpu]}):
yield target
+ # clear any test values fetched
+ spack.architecture.get_platform.cache.clear()
+
@pytest.mark.usefixtures('config', 'mock_packages')
class TestConcretize(object):