Skip to content

Cache compiler lookup per package#23988

Merged
sethrj merged 3 commits intospack:developfrom
haampie:fix/perf-1
May 28, 2021
Merged

Cache compiler lookup per package#23988
sethrj merged 3 commits intospack:developfrom
haampie:fix/perf-1

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented May 28, 2021

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 method would be called over 300 times during build-env

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
```
self.spec.architecture
)

return self._compiler
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap def compiler in @llnl.util.memoized for the same effect but with less new code?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never tried with a property but it should work. The order in case is:

@property
@llnl.util.lang.memoized
def compiler(self):
    ....

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, it seems we're hitting this python/mypy#1362 This is the first time we decorate a property, but:

  1. It's legit and works on Python 2
  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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

sethrj
sethrj previously approved these changes May 28, 2021
@sethrj
Copy link
Copy Markdown
Contributor

sethrj commented May 28, 2021

@alalazo weird error from mypy:

lib/spack/spack/package.py:1272: error: Decorated property not supported

is that an error in the package, or an internal limitation in mypy?

@alalazo
Copy link
Copy Markdown
Member

alalazo commented May 28, 2021

@sethrj See #23988 (comment)

@sethrj sethrj enabled auto-merge (squash) May 28, 2021 18:12
@sethrj sethrj merged commit f6febd2 into spack:develop May 28, 2021
RikkiButler20 pushed a commit to RikkiButler20/spack that referenced this pull request Jun 11, 2021
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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants