diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2023-08-16 14:33:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-16 14:33:03 +0200 |
commit | 4f07205c6376aeac4fa8d2e24db205441174b78f (patch) | |
tree | db487b46cd351f53afe705fccd343441e1c1993e /lib | |
parent | 08f9c7670eb00ee5221be4a3cfc0a905c151fe85 (diff) | |
download | spack-4f07205c6376aeac4fa8d2e24db205441174b78f.tar.gz spack-4f07205c6376aeac4fa8d2e24db205441174b78f.tar.bz2 spack-4f07205c6376aeac4fa8d2e24db205441174b78f.tar.xz spack-4f07205c6376aeac4fa8d2e24db205441174b78f.zip |
Avoid sort on singleton list during edge insertion (#39458)
The median length of this list of 1. For reasons I don't know, `.sort()`
still like to call the key function.
This saves ~9% of total database read time, and the number of calls
goes from 5305 -> 1715.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/spec.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py index a3b0920bf0..3d8887a773 100644 --- a/lib/spack/spack/spec.py +++ b/lib/spack/spack/spec.py @@ -985,16 +985,14 @@ class _EdgeMap(collections.abc.Mapping): def __len__(self): return len(self.edges) - def add(self, edge): - """Adds a new edge to this object. - - Args: - edge (DependencySpec): edge to be added - """ + def add(self, edge: DependencySpec): key = edge.spec.name if self.store_by_child else edge.parent.name - current_list = self.edges.setdefault(key, []) - current_list.append(edge) - current_list.sort(key=_sort_by_dep_types) + if key in self.edges: + lst = self.edges[key] + lst.append(edge) + lst.sort(key=_sort_by_dep_types) + else: + self.edges[key] = [edge] def __str__(self): return "{deps: %s}" % ", ".join(str(d) for d in sorted(self.values())) |