summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2019-12-02 23:05:02 +0100
committerTodd Gamblin <tgamblin@llnl.gov>2019-12-02 14:05:35 -0800
commita93a6136682debfd58d295e3035ad2c6d142bda1 (patch)
tree8665dfce9a735d5284bd542a671a32702f1e4dbe /lib
parentc36d9f297fafd1f9a1fd3d309a46eb3ee8987f44 (diff)
downloadspack-a93a6136682debfd58d295e3035ad2c6d142bda1.tar.gz
spack-a93a6136682debfd58d295e3035ad2c6d142bda1.tar.bz2
spack-a93a6136682debfd58d295e3035ad2c6d142bda1.tar.xz
spack-a93a6136682debfd58d295e3035ad2c6d142bda1.zip
Speedup environment activation (#13557)
* Add a transaction around repeated calls to `spec.prefix` in the activation process * cache the computation of home in the python package to speed up setting deps * ensure that module-scope variables are only set *once* per module
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_environment.py9
-rw-r--r--lib/spack/spack/environment.py6
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 84fc58587e..13ee99d177 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -422,6 +422,11 @@ def set_build_environment_variables(pkg, env, dirty):
def _set_variables_for_single_module(pkg, module):
"""Helper function to set module variables for single module."""
+ # Put a marker on this module so that it won't execute the body of this
+ # function again, since it is not needed
+ marker = '_set_run_already_called'
+ if getattr(module, marker, False):
+ return
jobs = spack.config.get('config:build_jobs') if pkg.parallel else 1
jobs = min(jobs, multiprocessing.cpu_count())
@@ -489,6 +494,10 @@ def _set_variables_for_single_module(pkg, module):
m.static_to_shared_library = static_to_shared_library
+ # Put a marker on this module so that it won't execute the body of this
+ # function again, since it is not needed
+ setattr(m, marker, True)
+
def set_module_variables_for_package(pkg):
"""Populate the module scope of install() with some useful functions.
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 55d513ee27..2c7a0cf098 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -159,7 +159,8 @@ def activate(
cmds += 'export PS1="%s ${PS1}";\n' % prompt
if add_view and default_view_name in env.views:
- cmds += env.add_default_view_to_shell(shell)
+ with spack.store.db.read_transaction():
+ cmds += env.add_default_view_to_shell(shell)
return cmds
@@ -207,7 +208,8 @@ def deactivate(shell='sh'):
cmds += 'fi;\n'
if default_view_name in _active_environment.views:
- cmds += _active_environment.rm_default_view_from_shell(shell)
+ with spack.store.db.read_transaction():
+ cmds += _active_environment.rm_default_view_from_shell(shell)
tty.debug("Deactivated environmennt '%s'" % _active_environment.name)
_active_environment = None