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-18 16:07:28 -0800
commit33335c9d0a4a64bb59a169795ef1afed2c8aa0ac (patch)
treea04d4cdf3a81b03ad82bf651f3ae802bab641c83 /lib
parent92c2c47f720d75c12e0bc1a30b92522e82770d58 (diff)
downloadspack-33335c9d0a4a64bb59a169795ef1afed2c8aa0ac.tar.gz
spack-33335c9d0a4a64bb59a169795ef1afed2c8aa0ac.tar.bz2
spack-33335c9d0a4a64bb59a169795ef1afed2c8aa0ac.tar.xz
spack-33335c9d0a4a64bb59a169795ef1afed2c8aa0ac.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 72cb3e57cc..494563b0cb 100644
--- a/lib/spack/spack/architecture.py
+++ b/lib/spack/spack/architecture.py
@@ -441,6 +441,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):