# HG changeset patch # User Pierre-Yves David # Date 1710462717 -3600 # Node ID c9ceb4f6025690167bdb245e530de6bac8baae95 # Parent 6b2aeeec3ed001cceef27438543b58fcb0fbdb4e 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. diff -r 6b2aeeec3ed0 -r c9ceb4f60256 mercurial/phases.py --- 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)