phases: avoid a potentially costly dictionary interation in some case stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 25 Mar 2024 01:50:31 +0100
branchstable
changeset 51465 e0f92bd98c24
parent 51464 394ea4428163
child 51466 4ee50d98d35c
phases: avoid a potentially costly dictionary interation in some case If we retract for the draft phase, there is not non-public item to be retracted and we can skip this part. This part is was apparently super costly thanks to Python. On mozilla-try-2019-02-18, a perf::unbundle call with a 10 000 changesets bundle gives give use the following timing. e57d4b868a3e: 4.6 seconds ac1c75188440: 102.5 seconds this-changeset: 30.0 seconds So we recovered about ⅔ of the regression, the next changeset will give us the rest back.
mercurial/phases.py
--- a/mercurial/phases.py	Thu Mar 21 12:24:42 2024 +0100
+++ b/mercurial/phases.py	Mon Mar 25 01:50:31 2024 +0100
@@ -907,9 +907,10 @@
                         replaced_roots.add(r)
             sets = self._phasesets
             sets[targetphase].update(changed_revs)
-            for r, old in changed_revs.items():
-                if old > public:
-                    sets[old].discard(r)
+            if targetphase > draft:
+                for r, old in changed_revs.items():
+                    if old > public:
+                        sets[old].discard(r)
 
         if new_roots:
             assert changed_revs