Skip to content
Snippets Groups Projects
Unverified Commit 48befd67 authored by Todd Gamblin's avatar Todd Gamblin
Browse files

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()`
parent 37eac1a2
No related branches found
No related tags found
No related merge requests found
...@@ -436,6 +436,7 @@ def from_dict(d): ...@@ -436,6 +436,7 @@ def from_dict(d):
return arch_for_spec(spec) return arch_for_spec(spec)
@memoized
def get_platform(platform_name): def get_platform(platform_name):
"""Returns a platform object that corresponds to the given name.""" """Returns a platform object that corresponds to the given name."""
platform_list = all_platforms() platform_list = all_platforms()
......
...@@ -94,6 +94,10 @@ def current_host(request, monkeypatch): ...@@ -94,6 +94,10 @@ def current_host(request, monkeypatch):
# preferred target via packages.yaml # preferred target via packages.yaml
cpu, _, is_preference = request.param.partition('-') cpu, _, is_preference = request.param.partition('-')
target = llnl.util.cpu.targets[cpu] 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: if not is_preference:
monkeypatch.setattr(llnl.util.cpu, 'host', lambda: target) monkeypatch.setattr(llnl.util.cpu, 'host', lambda: target)
monkeypatch.setattr(spack.platforms.test.Test, 'default', cpu) monkeypatch.setattr(spack.platforms.test.Test, 'default', cpu)
...@@ -104,6 +108,9 @@ def current_host(request, monkeypatch): ...@@ -104,6 +108,9 @@ def current_host(request, monkeypatch):
with spack.config.override('packages:all', {'target': [cpu]}): with spack.config.override('packages:all', {'target': [cpu]}):
yield target yield target
# clear any test values fetched
spack.architecture.get_platform.cache.clear()
@pytest.mark.usefixtures('config', 'mock_packages') @pytest.mark.usefixtures('config', 'mock_packages')
class TestConcretize(object): class TestConcretize(object):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment