##// END OF EJS Templates
fix memory usage of revlog caches by limiting cache size [issue1639]
Matt Mackall -
r9097:431462bd default
parent child Browse files
Show More
@@ -1206,18 +1206,7 b' def grep(ui, repo, pattern, *pats, **opt'
1206 if opts.get('print0'):
1206 if opts.get('print0'):
1207 sep = eol = '\0'
1207 sep = eol = '\0'
1208
1208
1209 fcache = {}
1209 getfile = util.lrucachefunc(repo.file)
1210 forder = []
1211 def getfile(fn):
1212 if fn not in fcache:
1213 if len(fcache) > 20:
1214 del fcache[forder.pop(0)]
1215 fcache[fn] = repo.file(fn)
1216 else:
1217 forder.remove(fn)
1218
1219 forder.append(fn)
1220 return fcache[fn]
1221
1210
1222 def matchlines(body):
1211 def matchlines(body):
1223 begin = 0
1212 begin = 0
@@ -379,11 +379,11 b' class filectx(object):'
379 child[0][b1:b2] = parent[0][a1:a2]
379 child[0][b1:b2] = parent[0][a1:a2]
380 return child
380 return child
381
381
382 getlog = util.cachefunc(lambda x: self._repo.file(x))
382 getlog = util.lrucachefunc(lambda x: self._repo.file(x))
383 def getctx(path, fileid):
383 def getctx(path, fileid):
384 log = path == self._path and self._filelog or getlog(path)
384 log = path == self._path and self._filelog or getlog(path)
385 return filectx(self._repo, path, fileid=fileid, filelog=log)
385 return filectx(self._repo, path, fileid=fileid, filelog=log)
386 getctx = util.cachefunc(getctx)
386 getctx = util.lrucachefunc(getctx)
387
387
388 def parents(f):
388 def parents(f):
389 # we want to reuse filectx objects as much as possible
389 # we want to reuse filectx objects as much as possible
@@ -120,8 +120,8 b' def copies(repo, c1, c2, ca, checkdirs=F'
120 return c1.filectx(f)
120 return c1.filectx(f)
121 return c2.filectx(f)
121 return c2.filectx(f)
122 return repo.filectx(f, fileid=n)
122 return repo.filectx(f, fileid=n)
123 ctx = util.cachefunc(makectx)
124
123
124 ctx = util.lrucachefunc(makectx)
125 copy = {}
125 copy = {}
126 fullcopy = {}
126 fullcopy = {}
127 diverge = {}
127 diverge = {}
@@ -115,6 +115,33 b' def cachefunc(func):'
115
115
116 return f
116 return f
117
117
118 def lrucachefunc(func):
119 '''cache most recent results of function calls'''
120 cache = {}
121 order = []
122 if func.func_code.co_argcount == 1:
123 def f(arg):
124 if arg not in cache:
125 if len(cache) > 20:
126 del cache[order.pop(0)]
127 cache[arg] = func(arg)
128 else:
129 order.remove(arg)
130 order.append(arg)
131 return cache[arg]
132 else:
133 def f(*args):
134 if args not in cache:
135 if len(cache) > 20:
136 del cache[order.pop(0)]
137 cache[args] = func(*args)
138 else:
139 order.remove(args)
140 order.append(args)
141 return cache[args]
142
143 return f
144
118 class propertycache(object):
145 class propertycache(object):
119 def __init__(self, func):
146 def __init__(self, func):
120 self.func = func
147 self.func = func
General Comments 0
You need to be logged in to leave comments. Login now