Conversation
Combined with spack#51535, spack#51536, spack#51367 and the reduced install task sleep time from spack#51491 this reduces the time for a no-op install of a development environment with 94 packages (including dependencies) from 8s to 2.8s for me. It also provides a similar reduction in time for `spack build-env --dump env.txt mypkg` which we frequently use to start a shell with the build environment. Signed-off-by: Victor Brunini <[email protected]>
|
Specs are mutable, this breaks the invariant |
Tangent to this PR, but I started looking at the concretize setup time for my development environment as well and it spends a large fraction of time formatting Spec's to strings repeatedly for the same Spec's. I hacked in a similar change to the initial pass of caching the hash from this PR, but now caching the result of |
|
Coming back to this (sorry for the delay). Related to your last comment, I'm wondering whether we could define class ImmutableSpec(Spec):
def __hash__(self):
try:
return self._immutable_hash
except AttributeError:
h = super().__hash()
self._immutable_hash = h
return h
# and the same for __str__and then construct objects like these in directives.py. Another possible advantage is that you can define the empty spec as a constant: and use that in directives that don't have a when condition, instead of constructing a new empty spec. That is advantageous because Python has a fast path in dicts and sets when |
|
And regarding |
|
I've tried this PR, and my suggestion, but neither are significant improvements. |
|
Also, just to confirm my original concern (no longer relevant after the change in this PR): we do mutate specs in various places, so freezing certain properties can be dangerous. I noticed the following examples:
|
|
@vbrunini there have been many PRs recently aimed to speed up the Python bits of Spack, from #51819 to micro optimizations like #51841. Setup time has reduced by >25% over the last week. We also socialized the idea that, by convention, Spec objects should be immutable, whether abstract or concrete. At this point:
I'm still not sure whether caching Rebasing your PR I see about a For concretization I see a I would consider that significant. Do you wanna revisit this PR? |
|
I think something like this is sufficient? if not self._dependencies: # fast path for trivial abstract specs (followed 94% in my tests)
return hash((
self.name, # cheap
self.namespace, # cheap
self.versions,
self.variants if self.variants.dict else None, # avoids expensive function call
self.architecture,
self.abstract_hash, # cheap
)) |
ea62170 to
164ca77
Compare
Signed-off-by: Victor Brunini <[email protected]>
This gives similar performance to caching the hash in the prior commit but should avoid the issues with Spec's being mutable brought up in review. Signed-off-by: Victor Brunini <[email protected]>
Signed-off-by: Victor Brunini <[email protected]>
Timing "spack-python -c 'import spack.repo; x = list(spack.repo.PATH.all_package_classes())'" I see: Before: 15.5s After: 14.8s Signed-off-by: Victor Brunini <[email protected]>
164ca77 to
abcd135
Compare
Signed-off-by: Victor Brunini <[email protected]>
Split out of #51518 based on reviewer comments @haampie