summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-18 14:25:21 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-18 16:07:28 -0800
commita3799b2c7bc8224f7cc4453e5cd6fdbea2cc71f1 (patch)
tree6139c87a29680c2d3ca0e7003b1a4303192feedd /lib
parent0e9c8d236cc4b75e929d6212245a517d3847dc5d (diff)
downloadspack-a3799b2c7bc8224f7cc4453e5cd6fdbea2cc71f1.tar.gz
spack-a3799b2c7bc8224f7cc4453e5cd6fdbea2cc71f1.tar.bz2
spack-a3799b2c7bc8224f7cc4453e5cd6fdbea2cc71f1.tar.xz
spack-a3799b2c7bc8224f7cc4453e5cd6fdbea2cc71f1.zip
performance: speed up `spack find` in environments
`Environment.added_specs()` has a loop around calls to `Package.installed()`, which can result in repeated DB queries. Optimize this with a read transaction in `Environment`.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 2be355df2d..61028506c1 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -25,6 +25,7 @@ import spack.hash_types as ht
import spack.repo
import spack.schema.env
import spack.spec
+import spack.store
import spack.util.spack_json as sjson
import spack.util.spack_yaml as syaml
import spack.config
@@ -1235,13 +1236,16 @@ class Environment(object):
Yields the user spec for non-concretized specs, and the concrete
spec for already concretized but not yet installed specs.
"""
- concretized = dict(self.concretized_specs())
- for spec in self.user_specs:
- concrete = concretized.get(spec)
- if not concrete:
- yield spec
- elif not concrete.package.installed:
- yield concrete
+ # use a transaction to avoid overhead of repeated calls
+ # to `package.installed`
+ with spack.store.db.read_transaction():
+ concretized = dict(self.concretized_specs())
+ for spec in self.user_specs:
+ concrete = concretized.get(spec)
+ if not concrete:
+ yield spec
+ elif not concrete.package.installed:
+ yield concrete
def concretized_specs(self):
"""Tuples of (user spec, concrete spec) for all concrete specs."""