Cache compiler lookup per package (#23988)

Before:

```
$ hyperfine '~/spack/bin/spack -e . build-env rocfft'
Benchmark #1: ~/spack/bin/spack -e . build-env rocfft
  Time (mean ± σ):      1.593 s ±  0.016 s    [User: 1.468 s, System: 0.126 s]
  Range (min … max):    1.575 s …  1.628 s    10 runs
```

After:

```
$ hyperfine '~/spack/bin/spack -e . build-env rocfft'
Benchmark #1: ~/spack/bin/spack -e . build-env rocfft
  Time (mean ± σ):      1.407 s ±  0.020 s    [User: 1.280 s, System: 0.127 s]
  Range (min … max):    1.393 s …  1.455 s    10 runs
```
This commit is contained in:
Harmen Stoppels 2021-05-28 23:36:34 +02:00 committed by GitHub
parent 7490d63c38
commit f6febd2ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1269,11 +1269,13 @@ def architecture(self):
raise ValueError("Can only get the arch for concrete package.")
return spack.architecture.arch_for_spec(self.spec.architecture)
@property
@property # type: ignore
@memoized
def compiler(self):
"""Get the spack.compiler.Compiler object used to build this package"""
if not self.spec.concrete:
raise ValueError("Can only get a compiler for a concrete package.")
return spack.compilers.compiler_for_spec(self.spec.compiler,
self.spec.architecture)