summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-12-19 16:07:22 +0100
committerGitHub <noreply@github.com>2020-12-19 07:07:22 -0800
commit4901728c5bb9e16756845a1e046c0e1063b0de66 (patch)
tree0c63cd7a5cdcf80a47abd37c15f49028f20055b9
parent71c77fa8fa351f7ed94f914175456da5f432bc31 (diff)
downloadspack-4901728c5bb9e16756845a1e046c0e1063b0de66.tar.gz
spack-4901728c5bb9e16756845a1e046c0e1063b0de66.tar.bz2
spack-4901728c5bb9e16756845a1e046c0e1063b0de66.tar.xz
spack-4901728c5bb9e16756845a1e046c0e1063b0de66.zip
asp: memoize the list of all target_specs to speed-up setup phase (#20473)
* asp: memoize the list of all target_specs to speed-up setup phase * asp: memoize using a cache per solver object
-rw-r--r--lib/spack/spack/solver/asp.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index c5dbcb0151..1b59337a09 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -497,6 +497,9 @@ class SpackSolverSetup(object):
# id for dummy variables
self.card = 0
+ # Caches to optimize the setup phase of the solver
+ self.target_specs_cache = None
+
def pkg_version_rules(self, pkg):
"""Output declared versions of a package.
@@ -910,10 +913,14 @@ class SpackSolverSetup(object):
def preferred_targets(self, pkg_name):
key_fn = spack.package_prefs.PackagePrefs(pkg_name, 'target')
- target_specs = [
- spack.spec.Spec('target={0}'.format(target_name))
- for target_name in archspec.cpu.TARGETS
- ]
+
+ if not self.target_specs_cache:
+ self.target_specs_cache = [
+ spack.spec.Spec('target={0}'.format(target_name))
+ for target_name in archspec.cpu.TARGETS
+ ]
+
+ target_specs = self.target_specs_cache
preferred_targets = [x for x in target_specs if key_fn(x) < 0]
if not preferred_targets:
return