Patchwork D6421: copies: avoid unnecessary copying of copy dict

login
register
mail settings
Submitter phabricator
Date May 22, 2019, 12:32 a.m.
Message ID <differential-rev-PHID-DREV-rs6sungclatmgvb25vui-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40175/
State New
Headers show

Comments

phabricator - May 22, 2019, 12:32 a.m.
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




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

Patch

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]