diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2018-03-24 07:39:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-24 07:39:10 -0700 |
commit | af0f94a1af62aa29ed5b91eeaeccba519d6ee8c4 (patch) | |
tree | 8f97d509d4eb876442b54cd91d4c7655923321ec | |
parent | 998b5a6482e77cc17b1fca2e248d2bd3d8bf3a60 (diff) | |
download | spack-af0f94a1af62aa29ed5b91eeaeccba519d6ee8c4.tar.gz spack-af0f94a1af62aa29ed5b91eeaeccba519d6ee8c4.tar.bz2 spack-af0f94a1af62aa29ed5b91eeaeccba519d6ee8c4.tar.xz spack-af0f94a1af62aa29ed5b91eeaeccba519d6ee8c4.zip |
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.
-rw-r--r-- | lib/spack/spack/repository.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/spack/spack/repository.py b/lib/spack/spack/repository.py index ec5e7ddc44..a3cac95c3b 100644 --- a/lib/spack/spack/repository.py +++ b/lib/spack/spack/repository.py @@ -683,7 +683,7 @@ class Repo(object): 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 @@ class Repo(object): 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 @@ class Repo(object): 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.""" |