Mercurial > hg-stable
changeset 40152:adbf8ca239e4
revlog: optimize ancestors() to not check filtered revisions for each
While reviewing the Rust implementation, I noticed iter(ancestors) doesn't
need to check filtering state for each parent revision. And doing that appears
to have some measurable perf win.
$ hg perfancestors -R mercurial
(orig) wall 0.038093 comb 0.040000 user 0.040000 sys 0.000000 (best of 100)
(this) wall 0.024795 comb 0.020000 user 0.020000 sys 0.000000 (best of 117)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 12 Oct 2018 06:22:43 +0200 |
parents | 38ac525b44c9 |
children | 0ae20d2141ed |
files | mercurial/revlog.py |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Thu Oct 11 21:51:17 2018 -0400 +++ b/mercurial/revlog.py Fri Oct 12 06:22:43 2018 +0200 @@ -648,6 +648,9 @@ return entry[5], entry[6] + # fast parentrevs(rev) where rev isn't filtered + _uncheckedparentrevs = parentrevs + def node(self, rev): try: return self.index[rev][7] @@ -747,8 +750,14 @@ See the documentation for ancestor.lazyancestors for more details.""" - return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev, - inclusive=inclusive) + # first, make sure start revisions aren't filtered + revs = list(revs) + checkrev = self.node + for r in revs: + checkrev(r) + # and we're sure ancestors aren't filtered as well + return ancestor.lazyancestors(self._uncheckedparentrevs, revs, + stoprev=stoprev, inclusive=inclusive) def descendants(self, revs): return dagop.descendantrevs(revs, self.revs, self.parentrevs)