[PATCH 2 of 2] treemanifest: speed up 4x tree to flat manifest conversion

Laurent Charignon lcharignon at fb.com
Thu Feb 4 12:27:10 EST 2016


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1454606782 28800
#      Thu Feb 04 09:26:22 2016 -0800
# Branch stable
# Node ID b163d0993d788fb7c5a55a8a052b1115ba7b66e6
# Parent  241c38b8b3acbf8d2ab57fa85a38e337ef4e2472
treemanifest: speed up 4x tree to flat manifest conversion

On our big repos we have a 4x speed improvement in tree to flat manifest
conversion:

Before this patch
~/hg/hg perftreemanifesttotext
! wall 25.622450 comb 25.590000 user 25.410000 sys 0.180000 (best of 3)

After this patch
~/hg/hg perftreemanifesttotext
! wall 6.541120 comb 6.540000 user 6.470000 sys 0.070000 (best of 3)

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -848,10 +848,20 @@
 
     def text(self, usemanifestv2=False):
         """Get the full data of this manifest as a bytestring."""
-        self._load()
-        flags = self.flags
-        return _text(((f, self[f], flags(f)) for f in self.keys()),
-                     usemanifestv2)
+        tovisit = []
+        visit = tovisit.pop
+        tovisit.append(self)
+        res = []
+
+        while tovisit:
+            n = visit()
+            n._load()
+            tovisit.extend(n._dirs.values())
+            dirpath = n._dir
+            getflags = n._flags.get
+            res.extend([(dirpath + f, u, getflags(f, ''))
+                       for (f, u) in n._files.items()])
+        return _text(sorted(res), usemanifestv2)
 
     def dirtext(self, usemanifestv2=False):
         """Get the full data of this directory as a bytestring. Make sure that


More information about the Mercurial-devel mailing list