revlog: speed up chunkcache
authorMatt Mackall <mpm@selenic.com>
Mon, 23 Jul 2007 20:44:08 -0500
changeset 4988 14486eea8e7a
parent 4987 8d30004ada40
child 4989 1aaed3d69772
revlog: speed up chunkcache - use a reasonable cache size - avoid an extra copy when we pull in big revs
mercurial/bundlerepo.py
mercurial/revlog.py
--- a/mercurial/bundlerepo.py	Mon Jul 23 20:44:08 2007 -0500
+++ b/mercurial/bundlerepo.py	Mon Jul 23 20:44:08 2007 -0500
@@ -77,7 +77,7 @@
         # not against rev - 1
         # XXX: could use some caching
         if not self.bundle(rev):
-            return revlog.revlog.chunk(self, rev, df, cachelen)
+            return revlog.revlog.chunk(self, rev, df)
         self.bundlefile.seek(self.start(rev))
         return self.bundlefile.read(self.length(rev))
 
--- a/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
+++ b/mercurial/revlog.py	Mon Jul 23 20:44:08 2007 -0500
@@ -838,16 +838,15 @@
         """apply a list of patches to a string"""
         return mdiff.patches(t, pl)
 
-    def chunk(self, rev, df=None, cachelen=4096):
+    def chunk(self, rev, df=None):
         start, length = self.start(rev), self.length(rev)
-        inline = self._inline
-        if inline:
+        if self._inline:
             start += (rev + 1) * self._io.size
         end = start + length
         def loadcache(df):
-            cache_length = max(cachelen, length) # 4k
+            cache_length = max(65536, length)
             if not df:
-                if inline:
+                if self._inline:
                     df = self.opener(self.indexfile)
                 else:
                     df = self.opener(self.datafile)
@@ -866,7 +865,12 @@
             loadcache(df)
             offset = 0
 
-        return decompress(self._chunkcache[1][offset:offset + length])
+        # avoid copying large chunks
+        c = self._chunkcache[1]
+        if len(c) > length:
+            c = c[offset:offset + length]
+
+        return decompress(c)
 
     def delta(self, node):
         """return or calculate a delta between a node and its predecessor"""