Patchwork [5,of,5] copies: split the combination of the copies mapping in its own function

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 2, 2019, 11:28 a.m.
Message ID <e3744ab9aaeef27f8b7f.1575286100@nodosa.octobus.net>
Download mbox | patch
Permalink /patch/43559/
State Accepted
Headers show

Comments

Pierre-Yves David - Dec. 2, 2019, 11:28 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1573674133 -3600
#      Wed Nov 13 20:42:13 2019 +0100
# Node ID e3744ab9aaeef27f8b7f62bf065b0038c674b486
# Parent  3348c01c4f299189d5f3ad208cea1bc635a57766
# EXP-Topic patch-copies-rust-prep
# Available At https://dev.heptapod.net/octobus/mercurial-devel/
#              hg pull https://dev.heptapod.net/octobus/mercurial-devel/ -r e3744ab9aaee
copies: split the combination of the copies mapping in its own function

In some case, this part take up to 95% of the copy tracing that take about a
hundred second. This poor performance comes from the fact we keep duplciating
and merging dictionary that are mostly similar.

I want to experiment with smarter native code to do this, so I need to isolate
the function first.

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -281,9 +281,25 @@  def _changesetforwardcopies(a, b, match)
     iterrevs &= mrset
     iterrevs.update(roots)
     iterrevs.remove(b.rev())
+    revs = sorted(iterrevs)
+    return _combinechangesetcopies(revs, children, b.rev(), revinfo, match)
+
+
+def _combinechangesetcopies(revs, children, targetrev, revinfo, match):
+    """combine the copies information for each item of iterrevs
+
+    revs: sorted iterable of revision to visit
+    children: a {parent: [children]} mapping.
+    targetrev: the final copies destination revision (not in iterrevs)
+    revinfo(rev): a function that return (p1, p2, p1copies, p2copies, removed)
+    match: a matcher
+
+
+    It returns the agregrated copies information for `targetrev`.
+    """
     all_copies = {}
     alwaysmatch = match.always()
-    for r in sorted(iterrevs):
+    for r in revs:
         copies = all_copies.pop(r, None)
         if copies is None:
             # this is a root
@@ -336,7 +352,7 @@  def _changesetforwardcopies(a, b, match)
                 else:
                     newcopies.update(othercopies)
                     all_copies[c] = newcopies
-    return all_copies[b.rev()]
+    return all_copies[targetrev]
 
 
 def _forwardcopies(a, b, base=None, match=None):