Reduce index memory usage by storing the bare string instead of tuples
authormason@suse.com
Tue, 04 Apr 2006 19:00:40 -0400
changeset 2080 1cbb14c048cb
parent 2079 ee96ca273f32
child 2081 416d8b2a75b8
Reduce index memory usage by storing the bare string instead of tuples Storing the tuple returned by struct.unpack significantly increases the memory required to store the entire index in ram. This patch uses struct.unpack on demand instead.
mercurial/revlog.py
--- a/mercurial/revlog.py	Tue Apr 04 16:47:12 2006 -0400
+++ b/mercurial/revlog.py	Tue Apr 04 19:00:40 2006 -0400
@@ -135,9 +135,9 @@
         for x in xrange(lend):
             if self.index[i + x] == None:
                 b = data[off : off + self.s]
-                e = struct.unpack(self.format, b)
-                self.index[i + x] = e
-                self.map[e[-1]] = i + x
+                self.index[i + x] = b
+                n = b[self.shaoffset:self.shaoffset + 20]
+                self.map[n] = i + x
             off += self.s
 
     def findnode(self, node):
@@ -218,7 +218,10 @@
         self.p.loadindex(pos)
         return self.p.index[pos]
     def __getitem__(self, pos):
-        return self.p.index[pos] or self.load(pos)
+        ret = self.p.index[pos] or self.load(pos)
+        if isinstance(ret, str):
+            ret = struct.unpack(self.p.indexformat, ret)
+        return ret
     def __setitem__(self, pos, item):
         self.p.index[pos] = item
     def __delitem__(self, pos):
@@ -242,11 +245,13 @@
     def __iter__(self):
         yield nullid
         for i in xrange(self.p.l):
-            try:
-                yield self.p.index[i][-1]
-            except:
+            ret = self.p.index[i]
+            if not ret:
                 self.p.loadindex(i)
-                yield self.p.index[i][-1]
+                ret = self.p.index[i]
+            if isinstance(ret, str):
+                ret = struct.unpack(self.p.indexformat, ret)
+            yield ret[-1]
     def __getitem__(self, key):
         try:
             return self.p.map[key]