D6421: copies: avoid unnecessary copying of copy dict

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed May 22 00:32:59 UTC 2019


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  When storing copy information in the changesets, this patch speeds up
  
    hg debugpathcopies FENNEC_58_0_2_BUILD1 FIREFOX_59_0b8_BUILD2
  
  from 11s to 5.9s. That command takes 6.2s when storing copy
  information in filelogs.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6421

AFFECTED FILES
  mercurial/copies.py

CHANGE DETAILS

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -297,7 +297,7 @@
         if r == b.rev():
             _filter(a, b, copies)
             return copies
-        for c in children[r]:
+        for i, c in enumerate(children[r]):
             childctx = repo[c]
             if r == childctx.p1().rev():
                 parent = 1
@@ -309,7 +309,13 @@
             if not match.always():
                 childcopies = {dst: src for dst, src in childcopies.items()
                                if match(dst)}
-            childcopies = _chain(copies, childcopies)
+            # Copy the dict only if later iterations will also need it
+            if i != len(children[r]) - 1:
+                copies = copies.copy()
+            if childcopies:
+                childcopies = _chain(copies, childcopies)
+            else:
+                childcopies = copies
             for f in childctx.filesremoved():
                 if f in childcopies:
                     del childcopies[f]



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list