Avoid stat-ing all packages at startup. (#7587)

- FastPackageChecker was being called at startup every time Spack runs,
  which takes a long time on networked filesystems.  Startup was taking
  5-7 seconds due to this call.

- The checker was intended to avaoid importing all packages (which is
  really expensive) when all it needs is to stat them.  So it's only
  "fast" for parts of the code that *need* it.

- This commit makes repositories instantiate the checker lazily, so it's
  only constructed when needed.
This commit is contained in:
Todd Gamblin 2018-03-24 07:39:10 -07:00 committed by GitHub
parent 998b5a6482
commit af0f94a1af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -683,7 +683,7 @@ def check(condition, msg):
self._instances = {}
# Maps that goes from package name to corresponding file stat
self._fast_package_checker = FastPackageChecker(self.packages_path)
self._fast_package_checker = None
# Index of virtual dependencies, computed lazily
self._provider_index = None
@ -928,9 +928,15 @@ def filename_for_package_name(self, spec):
pkg_dir = self.dirname_for_package_name(spec.name)
return join_path(pkg_dir, package_file_name)
@property
def _pkg_checker(self):
if self._fast_package_checker is None:
self._fast_package_checker = FastPackageChecker(self.packages_path)
return self._fast_package_checker
def all_package_names(self):
"""Returns a sorted list of all package names in the Repo."""
return sorted(self._fast_package_checker.keys())
return sorted(self._pkg_checker.keys())
def packages_with_tags(self, *tags):
v = set(self.all_package_names())
@ -952,7 +958,7 @@ def all_packages(self):
def exists(self, pkg_name):
"""Whether a package with the supplied name exists."""
return pkg_name in self._fast_package_checker
return pkg_name in self._pkg_checker
def is_virtual(self, pkg_name):
"""True if the package with this name is virtual, False otherwise."""