changeset 51505:c9ceb4f60256 stable 6.7

phases: avoid N² behavior in `advanceboundary` We allowed duplicated entries in the deque, which each entry could potentially insert all its ancestors. So advancing boundary for the full repository would mean each revision would walk all its ancestors, resulting in O(N²) iteration. For repository of any decent size, N² is quickly insane. We introduce a simple set to avoid this and get back to reasonable performance.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 15 Mar 2024 01:31:57 +0100
parents 6b2aeeec3ed0
children 7c83f0e82f70
files mercurial/phases.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/phases.py	Thu Mar 14 16:25:46 2024 +0100
+++ b/mercurial/phases.py	Fri Mar 15 01:31:57 2024 +0100
@@ -703,6 +703,7 @@
             return set()
 
         # search for affected high phase changesets and roots
+        seen = set(new_revs)
         push = heapq.heappush
         pop = heapq.heappop
         parents = cl.parentrevs
@@ -735,9 +736,11 @@
                 # higher phases
                 delroots.add(current)
             # schedule a walk down if needed
-            if p1_phase > targetphase:
+            if p1_phase > targetphase and p1 not in seen:
+                seen.add(p1)
                 push(revs, -p1)
-            if p2_phase > targetphase:
+            if p2_phase > targetphase and p2 not in seen:
+                seen.add(p2)
                 push(revs, -p2)
             if p1_phase < targetphase and p2_phase < targetphase:
                 new_target_roots.add(current)