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()`
This commit is contained in:
parent
92c2c47f72
commit
33335c9d0a
@ -441,6 +441,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):
|
|||||||
# 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):
|
|||||||
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user