summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2019-12-20 23:38:23 -0800
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-23 18:36:56 -0800
commit779ac9fe3e1968bbc8b267712c8827aba5dd985e (patch)
tree7debba9fd1ad221ba862f7fcebfbff717c867bbe /lib
parent99dee9037204d6bbf6d45f6e06a65fb21cfe50eb (diff)
downloadspack-779ac9fe3e1968bbc8b267712c8827aba5dd985e.tar.gz
spack-779ac9fe3e1968bbc8b267712c8827aba5dd985e.tar.bz2
spack-779ac9fe3e1968bbc8b267712c8827aba5dd985e.tar.xz
spack-779ac9fe3e1968bbc8b267712c8827aba5dd985e.zip
performance: avoid repeated DB locking on view generation
`ViewDescriptor.regenerate()` checks repeatedly whether packages are installed and also does a lot of DB queries. Put a read transaction around the whole thing to avoid repeatedly locking and unlocking the DB.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/environment.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 61028506c1..dd20bc3fda 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -516,20 +516,23 @@ class ViewDescriptor(object):
if spec.concrete: # Do not link unconcretized roots
specs_for_view.append(spec.copy(deps=('link', 'run')))
- installed_specs_for_view = set(s for s in specs_for_view
- if s in self and s.package.installed)
+ # regeneration queries the database quite a bit; this read
+ # transaction ensures that we don't repeatedly lock/unlock.
+ with spack.store.db.read_transaction():
+ installed_specs_for_view = set(
+ s for s in specs_for_view if s in self and s.package.installed)
- view = self.view()
+ view = self.view()
- view.clean()
- specs_in_view = set(view.get_all_specs())
- tty.msg("Updating view at {0}".format(self.root))
+ view.clean()
+ specs_in_view = set(view.get_all_specs())
+ tty.msg("Updating view at {0}".format(self.root))
- rm_specs = specs_in_view - installed_specs_for_view
- view.remove_specs(*rm_specs, with_dependents=False)
+ rm_specs = specs_in_view - installed_specs_for_view
+ view.remove_specs(*rm_specs, with_dependents=False)
- add_specs = installed_specs_for_view - specs_in_view
- view.add_specs(*add_specs, with_dependencies=False)
+ add_specs = installed_specs_for_view - specs_in_view
+ view.add_specs(*add_specs, with_dependencies=False)
class Environment(object):