##// END OF EJS Templates
revlog: use an LRU cache for delta chain bases...
Gregory Szorc -
r29830:92ac2baa default
parent child Browse files
Show More
@@ -225,9 +225,8 b' class revlog(object):'
225 self.opener = opener
225 self.opener = opener
226 # 3-tuple of (node, rev, text) for a raw revision.
226 # 3-tuple of (node, rev, text) for a raw revision.
227 self._cache = None
227 self._cache = None
228 # 2-tuple of (rev, baserev) defining the base revision the delta chain
228 # Maps rev to chain base rev.
229 # begins at for a revision.
229 self._chainbasecache = util.lrucachedict(100)
230 self._basecache = None
231 # 2-tuple of (offset, data) of raw data from the revlog at an offset.
230 # 2-tuple of (offset, data) of raw data from the revlog at an offset.
232 self._chunkcache = (0, '')
231 self._chunkcache = (0, '')
233 # How much data to read and cache into the raw revlog data cache.
232 # How much data to read and cache into the raw revlog data cache.
@@ -340,7 +339,7 b' class revlog(object):'
340
339
341 def clearcaches(self):
340 def clearcaches(self):
342 self._cache = None
341 self._cache = None
343 self._basecache = None
342 self._chainbasecache.clear()
344 self._chunkcache = (0, '')
343 self._chunkcache = (0, '')
345 self._pcache = {}
344 self._pcache = {}
346
345
@@ -390,11 +389,17 b' class revlog(object):'
390 def length(self, rev):
389 def length(self, rev):
391 return self.index[rev][1]
390 return self.index[rev][1]
392 def chainbase(self, rev):
391 def chainbase(self, rev):
392 base = self._chainbasecache.get(rev)
393 if base is not None:
394 return base
395
393 index = self.index
396 index = self.index
394 base = index[rev][3]
397 base = index[rev][3]
395 while base != rev:
398 while base != rev:
396 rev = base
399 rev = base
397 base = index[rev][3]
400 base = index[rev][3]
401
402 self._chainbasecache[rev] = base
398 return base
403 return base
399 def chainlen(self, rev):
404 def chainlen(self, rev):
400 return self._chaininfo(rev)[0]
405 return self._chaininfo(rev)[0]
@@ -1430,10 +1435,7 b' class revlog(object):'
1430 delta = mdiff.textdiff(ptext, t)
1435 delta = mdiff.textdiff(ptext, t)
1431 data = self.compress(delta)
1436 data = self.compress(delta)
1432 l = len(data[1]) + len(data[0])
1437 l = len(data[1]) + len(data[0])
1433 if basecache[0] == rev:
1438 chainbase = self.chainbase(rev)
1434 chainbase = basecache[1]
1435 else:
1436 chainbase = self.chainbase(rev)
1437 dist = l + offset - self.start(chainbase)
1439 dist = l + offset - self.start(chainbase)
1438 if self._generaldelta:
1440 if self._generaldelta:
1439 base = rev
1441 base = rev
@@ -1448,9 +1450,6 b' class revlog(object):'
1448 prev = curr - 1
1450 prev = curr - 1
1449 offset = self.end(prev)
1451 offset = self.end(prev)
1450 delta = None
1452 delta = None
1451 if self._basecache is None:
1452 self._basecache = (prev, self.chainbase(prev))
1453 basecache = self._basecache
1454 p1r, p2r = self.rev(p1), self.rev(p2)
1453 p1r, p2r = self.rev(p1), self.rev(p2)
1455
1454
1456 # full versions are inserted when the needed deltas
1455 # full versions are inserted when the needed deltas
@@ -1514,7 +1513,7 b' class revlog(object):'
1514
1513
1515 if type(text) == str: # only accept immutable objects
1514 if type(text) == str: # only accept immutable objects
1516 self._cache = (node, curr, text)
1515 self._cache = (node, curr, text)
1517 self._basecache = (curr, chainbase)
1516 self._chainbasecache[curr] = chainbase
1518 return node
1517 return node
1519
1518
1520 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset):
1519 def _writeentry(self, transaction, ifh, dfh, entry, data, link, offset):
General Comments 0
You need to be logged in to leave comments. Login now