[patch 7/7] Optimize manifest.add.addlistdelta
Chris Mason
mason at suse.com
Mon Aug 22 12:44:41 CDT 2005
# HG changeset patch
# User mason at suse.com
Optimize manifest.add.addlistdelta
This optimizes addlistdelta to run on larger regions of the addlist
at a time. gendelta already had these optimizations to compress
the delta found in the main manifest.add loop, this patch just pulls
the compression out into a helper function, and the result of the
compression is sent to both addlistdelta and gendelta.
This patch turns:
addlist[1] = "new line 1"
addlist[2] = "new line 2"
addlist[3] = "new line 3"
Into
addlist[1:4] = ["new line1", "new line2", "new line3"]
Performance gain is only 3-4% in the common case, but it is much cleaner.
Index: mine/mercurial/hg.py
===================================================================
--- mine.orig/mercurial/hg.py 2005-08-22 13:18:24.000000000 -0400
+++ mine/mercurial/hg.py 2005-08-22 13:19:41.000000000 -0400
@@ -145,23 +145,34 @@ class manifest(revlog):
changed=None):
# directly generate the mdiff delta from the data collected during
# the bisect loop below
- def gendelta(delta):
+ def gendelta(addlist, delta):
+ result = []
+ for x in delta:
+ if x[2]:
+ s = "".join(x[2])
+ else:
+ s = ""
+ start = addlist.offset(x[0])
+ end = addlist.offset(x[1])
+ result.append(struct.pack(">lll", start, end, len(s)) + s)
+ return result
+ def compressdelta(delta):
i = 0
result = []
while i < len(delta):
- start = delta[i][2]
- end = delta[i][3]
- l = delta[i][4]
- if l == None:
- l = ""
- while i < len(delta) - 1 and start <= delta[i+1][2] \
- and end >= delta[i+1][2]:
- if delta[i+1][3] > end:
- end = delta[i+1][3]
- if delta[i+1][4]:
- l += delta[i+1][4]
+ start = delta[i][0]
+ end = delta[i][1]
+ l = []
+ if delta[i][2]:
+ l.append(delta[i][2])
+ while i < (len(delta) - 1) and start <= delta[i+1][0] \
+ and end >= delta[i+1][0]:
+ if delta[i+1][1] > end:
+ end = delta[i+1][1]
+ if delta[i+1][2]:
+ l.append(delta[i+1][2])
i += 1
- result.append(struct.pack(">lll", start, end, len(l)) + l)
+ result.append([start, end, l])
i += 1
return result
@@ -174,8 +185,8 @@ class manifest(revlog):
i -= 1
start = delta[i][0]
end = delta[i][1]
- if delta[i][4]:
- addlist[start:end] = [delta[i][4]]
+ if delta[i][2]:
+ addlist[start:end] = delta[i][2]
else:
del addlist[start:end]
return addlist
@@ -229,13 +240,14 @@ class manifest(revlog):
# item is found, replace/delete the existing line
start = bs - 1
end = bs
- delta.append((start, end, addlist.offset(start), addlist.offset(end), l))
+ delta.append([start, end, l])
- self.addlist = addlistdelta(addlist, delta)
+ cdelta = compressdelta(delta)
if self.mapcache[0] == self.tip():
- cachedelta = "".join(gendelta(delta))
+ cachedelta = "".join(gendelta(addlist, cdelta))
else:
cachedelta = None
+ self.addlist = addlistdelta(addlist, cdelta)
text = self.addlist.text()
n = self.addrevision(text, transaction, link, p1, p2, cachedelta)
--
More information about the Mercurial
mailing list