Mercurial > hg
changeset 42446:055c3e2c44f0
revlog: speed up isancestor
Currently, it is implemented on top of commonancestorsheads.
Implement it on top of reachableroots instead, as reachableroots could
stop walking the graph much sooner than commonancestorsheads.
Measuring repo.changelog.isancestorrev on two revisions in a private repository:
before: ! wall 0.005175 comb 0.010000 user 0.010000 sys 0.000000 (best of 550)
after : ! wall 0.000072 comb 0.000000 user 0.000000 sys 0.000000 (best of 36199)
When hg does this kind of operations 1500 times in pull ->
bookmarks.comparebookmarks -> bookmarks.validdest, that's 11s that
drop from the --profile output.
Differential Revision: https://phab.mercurial-scm.org/D6506
author | Valentin Gatien-Baron <vgatien-baron@janestreet.com> |
---|---|
date | Mon, 10 Jun 2019 13:23:14 -0400 |
parents | 3e42fc243741 |
children | cda591d2bfe1 |
files | mercurial/changelog.py mercurial/dagop.py mercurial/revlog.py |
diffstat | 3 files changed, 18 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/changelog.py Mon Jun 10 11:40:43 2019 -0400 +++ b/mercurial/changelog.py Mon Jun 10 13:23:14 2019 -0400 @@ -420,9 +420,6 @@ if i not in self.filteredrevs: yield i - def reachableroots(self, minroot, heads, roots, includepath=False): - return self.index.reachableroots2(minroot, heads, roots, includepath) - def _checknofilteredinrevs(self, revs): """raise the appropriate error if 'revs' contains a filtered revision
--- a/mercurial/dagop.py Mon Jun 10 11:40:43 2019 -0400 +++ b/mercurial/dagop.py Mon Jun 10 13:23:14 2019 -0400 @@ -259,11 +259,10 @@ yield rev break -def _reachablerootspure(repo, minroot, roots, heads, includepath): - """See reachableroots""" +def _reachablerootspure(pfunc, minroot, roots, heads, includepath): + """See revlog.reachableroots""" if not roots: return [] - parentrevs = repo.changelog.parentrevs roots = set(roots) visit = list(heads) reachable = set() @@ -280,7 +279,7 @@ reached(rev) if not includepath: continue - parents = parentrevs(rev) + parents = pfunc(rev) seen[rev] = parents for parent in parents: if parent >= minroot and parent not in seen: @@ -296,18 +295,13 @@ return reachable def reachableroots(repo, roots, heads, includepath=False): - """return (heads(::<roots> and <roots>::<heads>)) - - If includepath is True, return (<roots>::<heads>).""" + """See revlog.reachableroots""" if not roots: return baseset() minroot = roots.min() roots = list(roots) heads = list(heads) - try: - revs = repo.changelog.reachableroots(minroot, heads, roots, includepath) - except AttributeError: - revs = _reachablerootspure(repo, minroot, roots, heads, includepath) + revs = repo.changelog.reachableroots(minroot, heads, roots, includepath) revs = baseset(revs) revs.sort() return revs
--- a/mercurial/revlog.py Mon Jun 10 11:40:43 2019 -0400 +++ b/mercurial/revlog.py Mon Jun 10 13:23:14 2019 -0400 @@ -1216,14 +1216,25 @@ A revision is considered an ancestor of itself. The implementation of this is trivial but the use of - commonancestorsheads is not.""" + reachableroots is not.""" if a == nullrev: return True elif a == b: return True elif a > b: return False - return a in self._commonancestorsheads(a, b) + return bool(self.reachableroots(a, [b], [a], includepath=False)) + + def reachableroots(self, minroot, heads, roots, includepath=False): + """return (heads(::<roots> and <roots>::<heads>)) + + If includepath is True, return (<roots>::<heads>).""" + try: + return self.index.reachableroots2(minroot, heads, roots, + includepath) + except AttributeError: + return dagop._reachablerootspure(self.parentrevs, + minroot, roots, heads, includepath) def ancestor(self, a, b): """calculate the "best" common ancestor of nodes a and b"""