Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/statichttprepo.py Tue Jul 11 02:10:04 2017 +0900 +++ b/mercurial/statichttprepo.py Sat Jul 01 20:51:19 2017 -0700 @@ -165,6 +165,8 @@ self.encodepats = None self.decodepats = None self._transref = None + # Cache of types representing filtered repos. + self._filteredrepotypes = {} def _restrictcapabilities(self, caps): caps = super(statichttprepository, self)._restrictcapabilities(caps)