Mercurial > evolve
changeset 2209:d25d39b88c7f
stablerange: cache parents
We happens to be doing and awful amount of parent call. We cache them locally
for efficiency.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Fri, 24 Mar 2017 05:15:25 +0100 |
parents | 781ab704dc59 |
children | 37bd878d2e58 |
files | hgext3rd/evolve/stablerange.py |
diffstat | 1 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/stablerange.py Thu Mar 23 12:53:39 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Fri Mar 24 05:15:25 2017 +0100 @@ -174,6 +174,8 @@ # the revision computed anyway, and passing that knowledge around might # help to slice one of its subranges also containings a merge. self._revsinrangecache = {} + # caching parent call # as we do so many of them + self._parentscache = {} def warmup(self, repo, heads): """warm the cache up to 'heads'""" @@ -194,7 +196,7 @@ if revdepth is not None: stack.pop() continue - p1, p2 = cl.parentrevs(current) + p1, p2 = self._parents(current, cl.parentrevs) if p1 == nullrev: # root case revdepth = 1 @@ -249,6 +251,13 @@ assert len(revs) == self.rangelength(repo, rangeid) return revs + def _parents(self, rev, func): + parents = self._parentscache.get(rev) + if parents is None: + parents = func(rev) + self._parentscache[rev] = parents + return parents + @staticmethod def _depthmerge(cl, rev, p1, p2, stack, cache): # sub method to simplify the main 'depthrev' one @@ -319,7 +328,7 @@ This function also have the important task to update the revscache of the parent revs if possible and needed""" # is this is a merge, there is not need to prepare the parents. - p1, p2 = repo.changelog.parentrevs(rangeid[0]) + p1, p2 = self._parents(rangeid[0], repo.changelog.parentrevs) if p2 != nodemod.nullrev: return None parentrange = (p1, rangeid[1]) @@ -354,7 +363,7 @@ return slicepoint def _slicesrangeat(self, repo, rangeid, globalindex): - p1, p2 = repo.changelog.parentrevs(rangeid[0]) + p1, p2 = self._parents(rangeid[0], repo.changelog.parentrevs) if p2 != nodemod.nullrev: return self._slicesrangeatmerge(repo, rangeid, globalindex) assert p1 != nodemod.nullrev @@ -402,9 +411,10 @@ else: bheads = set(bottomrevs) parentrevs = cl.parentrevs + parents = self._parents du = bheads.difference_update for r in bottomrevs: - du(parentrevs(r)) + du(parents(r, parentrevs)) # if len(bheads) == 1: # assert 1 == len(repo.revs('roots(%ld)', top._revs)) if len(bheads) == 1: