comparison mercurial/statichttprepo.py @ 33389:7e89bd0cfb86

localrepo: cache types for filtered repos (issue5043) Python introduces a reference cycle on dynamically created types via __mro__, making them very easy to leak. See https://bugs.python.org/issue17950. Previously, repo.filtered() created a type on every invocation. Long-running processes (like `hg convert`) could call this function thousands of times, leading to a steady memory leak. Since we're Unable to stop the leak because this is a bug in Python, the next best thing is to contain it. This patch adds a cache of of the dynamically generated repoview/filter types on the localrepo object. Since we only generate each type once, we cap the amount of memory that can leak to something reasonable. After this change, `hg convert` no longer leaks memory on every revision. The process will likely grow memory usage over time due to e.g. larger manifests. But there are no leaks.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 01 Jul 2017 20:51:19 -0700
parents b8ff7d0ff361
children 4133c0b0fcd7
comparison
equal deleted inserted replaced
33388:0823f0983eaa 33389:7e89bd0cfb86
163 self._branchcaches = {} 163 self._branchcaches = {}
164 self._revbranchcache = None 164 self._revbranchcache = None
165 self.encodepats = None 165 self.encodepats = None
166 self.decodepats = None 166 self.decodepats = None
167 self._transref = None 167 self._transref = None
168 # Cache of types representing filtered repos.
169 self._filteredrepotypes = {}
168 170
169 def _restrictcapabilities(self, caps): 171 def _restrictcapabilities(self, caps):
170 caps = super(statichttprepository, self)._restrictcapabilities(caps) 172 caps = super(statichttprepository, self)._restrictcapabilities(caps)
171 return caps.difference(["pushkey"]) 173 return caps.difference(["pushkey"])
172 174