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

Memoize all_specs() and exists() for better performance.

- Real bottleneck is calling normalize() for every spec when we read it.
- Need to store graph information in spec files to avoid the need for this.
  - Also, normalizing old specs isn't always possible, so we need to do this anyway.
parent 3c0048dd
Branches
Tags
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
from contextlib import closing from contextlib import closing
import llnl.util.tty as tty import llnl.util.tty as tty
from llnl.util.lang import memoized
from llnl.util.filesystem import join_path, mkdirp from llnl.util.filesystem import join_path, mkdirp
import spack import spack
...@@ -223,6 +224,9 @@ def read_spec(self, path): ...@@ -223,6 +224,9 @@ def read_spec(self, path):
if all(spack.db.exists(s.name) for s in spec.traverse()): if all(spack.db.exists(s.name) for s in spec.traverse()):
copy = spec.copy() copy = spec.copy()
# TODO: It takes a lot of time to normalize every spec on read.
# TODO: Storing graph info with spec files would fix this.
copy.normalize() copy.normalize()
if copy.concrete: if copy.concrete:
return copy # These are specs spack still understands. return copy # These are specs spack still understands.
...@@ -276,17 +280,20 @@ def make_path_for_spec(self, spec): ...@@ -276,17 +280,20 @@ def make_path_for_spec(self, spec):
self.write_spec(spec, spec_file_path) self.write_spec(spec, spec_file_path)
@memoized
def all_specs(self): def all_specs(self):
if not os.path.isdir(self.root): if not os.path.isdir(self.root):
return return []
specs = []
for path in traverse_dirs_at_depth(self.root, 3): for path in traverse_dirs_at_depth(self.root, 3):
arch, compiler, last_dir = path arch, compiler, last_dir = path
spec_file_path = join_path( spec_file_path = join_path(
self.root, arch, compiler, last_dir, self.spec_file_name) self.root, arch, compiler, last_dir, self.spec_file_name)
if os.path.exists(spec_file_path): if os.path.exists(spec_file_path):
spec = self.read_spec(spec_file_path) spec = self.read_spec(spec_file_path)
yield spec specs.append(spec)
return specs
def extension_file_path(self, spec): def extension_file_path(self, spec):
......
...@@ -192,6 +192,7 @@ def all_packages(self): ...@@ -192,6 +192,7 @@ def all_packages(self):
yield self.get(name) yield self.get(name)
@memoized
def exists(self, pkg_name): def exists(self, pkg_name):
"""Whether a package with the supplied name exists .""" """Whether a package with the supplied name exists ."""
return os.path.exists(self.filename_for_package_name(pkg_name)) return os.path.exists(self.filename_for_package_name(pkg_name))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment