Cache compiler lookup per package#23988
Conversation
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 ```
lib/spack/spack/package.py
Outdated
| self.spec.architecture | ||
| ) | ||
|
|
||
| return self._compiler |
There was a problem hiding this comment.
Could you wrap def compiler in @llnl.util.memoized for the same effect but with less new code?
There was a problem hiding this comment.
I never tried with a property but it should work. The order in case is:
@property
@llnl.util.lang.memoized
def compiler(self):
....There was a problem hiding this comment.
Meh, it seems we're hitting this python/mypy#1362 This is the first time we decorate a property, but:
- It's legit and works on Python 2
- The error detected is from an open issue that is stale since 2016?
So it feels somehow not an improvement to fix this with:
@property # type: ignore
@llnl.util.lang.memoized
def compiler(self):Can't we disable this check from mypy? @trws
There was a problem hiding this comment.
We cannot, other than with the ignore comment or ignoring the file. There just isn't an option to skip this error for whatever reason.
There was a problem hiding this comment.
We could add an internal function or method that is not a property with the memoized annotation that the property calls though. That would avoid the entire problem.
There was a problem hiding this comment.
We could add an internal function or method that is not a property with the memoized annotation that the property calls though. That would avoid the entire problem.
It doesn't seem a better solution. We are splitting a function into two just to work around an issue in a linter. Not a major problem, but it was somehow unexpected to see that nobody fixed it since 2016.
|
@alalazo weird error from mypy: is that an error in the package, or an internal limitation in mypy? |
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 ```
Before:
After:
This method would be called over 300 times during
build-env