From a2f8a2321d94a89ad1cb13e0dccca20e5f5aa325 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Tue, 28 Jan 2020 21:36:47 -0800 Subject: [PATCH] repo: avoid unnecessary spec parsing in `filename_for_package_name()` `filename_for_package_name()` and `dirname_for_package_name()` automatically construct a Spec from their arguments, which adds a fair amount of overhead to importing lots of packages. Removing this removes about 11% of the runtime of importing all packages in Spack (9s -> 8s). - [x] `filename_for_package_name()` and `dirname_for_package_name()` now take a string `pkg_name` arguments instead of specs. --- lib/spack/spack/repo.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index c95e889772..8e3dae5d47 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -932,7 +932,7 @@ def dump_provenance(self, spec, path): tty.warn("Patch file did not exist: %s" % patch.path) # Install the package.py file itself. - install(self.filename_for_package_name(spec), path) + install(self.filename_for_package_name(spec.name), path) def purge(self): """Clear entire package instance cache.""" @@ -974,20 +974,12 @@ def providers_for(self, vpkg_spec): def extensions_for(self, extendee_spec): return [p for p in self.all_packages() if p.extends(extendee_spec)] - def _check_namespace(self, spec): - """Check that the spec's namespace is the same as this repository's.""" - if spec.namespace and spec.namespace != self.namespace: - raise UnknownNamespaceError(spec.namespace) - - @autospec - def dirname_for_package_name(self, spec): + def dirname_for_package_name(self, pkg_name): """Get the directory name for a particular package. This is the directory that contains its package.py file.""" - self._check_namespace(spec) - return os.path.join(self.packages_path, spec.name) + return os.path.join(self.packages_path, pkg_name) - @autospec - def filename_for_package_name(self, spec): + def filename_for_package_name(self, pkg_name): """Get the filename for the module we should load for a particular package. Packages for a Repo live in ``$root//package.py`` @@ -996,8 +988,7 @@ def filename_for_package_name(self, spec): package doesn't exist yet, so callers will need to ensure the package exists before importing. """ - self._check_namespace(spec) - pkg_dir = self.dirname_for_package_name(spec.name) + pkg_dir = self.dirname_for_package_name(pkg_name) return os.path.join(pkg_dir, package_file_name) @property