Optimize uninstall selection in serialize_tasks.
authorZac Medico <zmedico@gentoo.org>
Fri, 15 Oct 2010 02:01:39 +0000 (19:01 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 15 Oct 2010 02:01:39 +0000 (19:01 -0700)
This increases performance dramatically in cases when there are
hundreds of blockers to solve, like when  when upgrading to a new slot
of kde-meta.

pym/_emerge/depgraph.py

index 31f97ec154c4f32042049945c58f6586a568e588..adef1193d11928faf8974206520f50640d4c7d21 100644 (file)
@@ -4168,9 +4168,6 @@ class depgraph(object):
                                min_parent_deps = None
                                uninst_task = None
 
-                               # FIXME: This loop can be extremely slow when
-                               #        there of lots of blockers to solve
-                               #        (especially the gather_deps part).
                                for task in myblocker_uninstalls.leaf_nodes():
                                        # Do some sanity checks so that system or world packages
                                        # don't get uninstalled inappropriately here (only really
@@ -4297,9 +4294,20 @@ class depgraph(object):
                                        self._spinner_update()
                                        mergeable_parent = False
                                        parent_deps = set()
+                                       parent_deps.add(task)
                                        for parent in mygraph.parent_nodes(task):
                                                parent_deps.update(mygraph.child_nodes(parent,
                                                        ignore_priority=priority_range.ignore_medium_soft))
+                                               if min_parent_deps is not None and \
+                                                       len(parent_deps) >= min_parent_deps:
+                                                       # This task is no better than a previously selected
+                                                       # task, so abort search now in order avoid wasting
+                                                       # any more cpu time on this task. This increases
+                                                       # performance dramatically in cases when there are
+                                                       # hundreds of blockers to solve, like when
+                                                       # when upgrading to a new slot of kde-meta.
+                                                       mergeable_parent = None
+                                                       break
                                                if parent in mergeable_nodes and \
                                                        gather_deps(ignore_uninst_or_med_soft,
                                                        mergeable_nodes, set(), parent):
@@ -4308,7 +4316,6 @@ class depgraph(object):
                                        if not mergeable_parent:
                                                continue
 
-                                       parent_deps.remove(task)
                                        if min_parent_deps is None or \
                                                len(parent_deps) < min_parent_deps:
                                                min_parent_deps = len(parent_deps)