diff --git a/src/modules/catalog.py b/src/modules/catalog.py index 4dcb3cecf..250af59b5 100644 --- a/src/modules/catalog.py +++ b/src/modules/catalog.py @@ -829,8 +829,20 @@ def sort(self, pfmris=None, pubs=None): If neither 'pfmris' or 'pubs' is provided, all entries will be sorted.""" + # Version objects are expensive to construct and the same + # version string commonly recurs across many stems (packages + # built and published together share branch and timestamp), so + # construct each distinct version only once per sort. + vcache = {} + def key_func(item): - return pkg.version.Version(item["version"]) + ver = item["version"] + try: + return vcache[ver] + except KeyError: + v = pkg.version.Version(ver) + vcache[ver] = v + return v self.load() if pfmris is not None: