diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2019-09-02 22:22:20 -0700 |
---|---|---|
committer | Todd Gamblin <tgamblin@llnl.gov> | 2019-09-03 07:41:38 -0700 |
commit | d79f85d763ee3601f54e8b48d56a779d28dd2947 (patch) | |
tree | a111812820853b2fc95c54f4fc48e11c1f2124c0 | |
parent | ae41ef914602b3d957f7567ee571b58a3ef32134 (diff) | |
download | spack-d79f85d763ee3601f54e8b48d56a779d28dd2947.tar.gz spack-d79f85d763ee3601f54e8b48d56a779d28dd2947.tar.bz2 spack-d79f85d763ee3601f54e8b48d56a779d28dd2947.tar.xz spack-d79f85d763ee3601f54e8b48d56a779d28dd2947.zip |
perf: spack find -p now does only one DB transaction
`spec.prefix` reads from Spack's database, and if you do this with
multiple consecutive read transactions, it can take a long time. Or, at
least, you can see the paths get written out one by one.
This uses an outer read transaction to ensure that actual disk locks are
acquired only once for the whole `spack find` operation, and that each
transaction inside `spec.prefix` is an in-memory operation. This speeds
up `spack find -p` a lot.
-rw-r--r-- | lib/spack/spack/cmd/__init__.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/spack/spack/cmd/__init__.py b/lib/spack/spack/cmd/__init__.py index 54496dc32d..cf6e3b7c3e 100644 --- a/lib/spack/spack/cmd/__init__.py +++ b/lib/spack/spack/cmd/__init__.py @@ -357,15 +357,18 @@ def display_specs(specs, args=None, **kwargs): max_width = max(len(f[0]) for f in formatted) path_fmt = "%%-%ds%%s" % (max_width + 2) - for string, spec in formatted: - if not string: - print() # print newline from above - continue - - if paths: - print(path_fmt % (string, spec.prefix)) - else: - print(string) + # getting lots of prefixes requires DB lookups. Ensure + # all spec.prefix calls are in one transaction. + with spack.store.db.read_transaction(): + for string, spec in formatted: + if not string: + print() # print newline from above + continue + + if paths: + print(path_fmt % (string, spec.prefix)) + else: + print(string) if groups: for specs in iter_groups(specs, indent, all_headers): |