Skip to content
Snippets Groups Projects
Unverified Commit a85b9070 authored by Todd Gamblin's avatar Todd Gamblin
Browse files

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.
parent 91ea90c2
No related branches found
No related tags found
No related merge requests found
...@@ -516,20 +516,23 @@ def regenerate(self, all_specs, roots): ...@@ -516,20 +516,23 @@ def regenerate(self, all_specs, roots):
if spec.concrete: # Do not link unconcretized roots if spec.concrete: # Do not link unconcretized roots
specs_for_view.append(spec.copy(deps=('link', 'run'))) specs_for_view.append(spec.copy(deps=('link', 'run')))
installed_specs_for_view = set(s for s in specs_for_view # regeneration queries the database quite a bit; this read
if s in self and s.package.installed) # 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() view.clean()
specs_in_view = set(view.get_all_specs()) specs_in_view = set(view.get_all_specs())
tty.msg("Updating view at {0}".format(self.root)) tty.msg("Updating view at {0}".format(self.root))
rm_specs = specs_in_view - installed_specs_for_view rm_specs = specs_in_view - installed_specs_for_view
view.remove_specs(*rm_specs, with_dependents=False) view.remove_specs(*rm_specs, with_dependents=False)
add_specs = installed_specs_for_view - specs_in_view add_specs = installed_specs_for_view - specs_in_view
view.add_specs(*add_specs, with_dependencies=False) view.add_specs(*add_specs, with_dependencies=False)
class Environment(object): class Environment(object):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment