Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 18988:5bae936764bb
parsers: a C implementation of the new ancestors algorithm
The performance of both the old and new Python ancestor algorithms
depends on the number of revs they need to traverse. Although the
new algorithm performs far better than the old when revs are
numerically and topologically close, both algorithms become slow
under other circumstances, taking up to 1.8 seconds to give answers
in a Linux kernel repo.
This C implementation of the new algorithm is a fairly straightforward
transliteration. The only corner case of interest is that it raises
an OverflowError if the number of GCA candidates found during the
first pass is greater than 24, to avoid the dual perils of fixnum
overflow and trying to allocate too much memory. (If this exception
is raised, the Python implementation is used instead.)
Performance numbers are good: in a Linux kernel repo, time for "hg
debugancestors" on two distant revs (24bf01de7537 and c2a8808f5943)
is as follows:
Old Python: 0.36 sec
New Python: 0.42 sec
New C: 0.02 sec
For a case where the new algorithm should perform well:
Old Python: 1.84 sec
New Python: 0.07 sec
New C: measures as zero when using --time
(This commit includes a paranoid cross-check to ensure that the
Python and C implementations give identical answers. The above
performance numbers were measured with that check disabled.)
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 16 Apr 2013 10:08:20 -0700 |
parents | 3605d4e7e618 |
children | 12a3474c1634 |
comparison
equal
deleted
inserted
replaced
18987:3605d4e7e618 | 18988:5bae936764bb |
---|---|
704 | 704 |
705 def ancestor(self, a, b): | 705 def ancestor(self, a, b): |
706 """calculate the least common ancestor of nodes a and b""" | 706 """calculate the least common ancestor of nodes a and b""" |
707 | 707 |
708 a, b = self.rev(a), self.rev(b) | 708 a, b = self.rev(a), self.rev(b) |
709 ancs = ancestor.ancestors(self.parentrevs, a, b) | 709 try: |
710 ancs = self.index.ancestors(a, b) | |
711 old = ancestor.ancestors(self.parentrevs, a, b) | |
712 assert set(ancs) == old, ('opinions differ over ancestor(%d, %d)' % | |
713 (a, b)) | |
714 except (AttributeError, OverflowError): | |
715 ancs = ancestor.ancestors(self.parentrevs, a, b) | |
710 if ancs: | 716 if ancs: |
711 # choose a consistent winner when there's a tie | 717 # choose a consistent winner when there's a tie |
712 return min(map(self.node, ancs)) | 718 return min(map(self.node, ancs)) |
713 return nullid | 719 return nullid |
714 | 720 |