Mercurial > hg > mercurial-source
diff mercurial/revset.py @ 26109:15412bba5a68
revset: prefetch all attributes before loop in _revsbetween
Python is slow at attributes lookup. No, really, I mean -slow-. prefetching
these three methods give use a measurable performance boost.
revset #0: 0::tip
plain
0) 0.037655
1) 0.034290 91%
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 11 Jun 2015 11:42:46 -0700 |
parents | 94441df6206c |
children | f140d6207cca |
line wrap: on
line diff
--- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -91,23 +91,27 @@ # (and if it is not, it should.) minroot = min(roots) roots = set(roots) + # prefetch all the things! (because python is slow) + reached = reachable.add + dovisit = visit.append + nextvisit = visit.pop # open-code the post-order traversal due to the tiny size of # sys.getrecursionlimit() while visit: - rev = visit.pop() + rev = nextvisit() if rev in roots: - reachable.add(rev) + reached(rev) parents = parentrevs(rev) seen[rev] = parents for parent in parents: if parent >= minroot and parent not in seen: - visit.append(parent) + dovisit(parent) if not reachable: return baseset() for rev in sorted(seen): for parent in seen[rev]: if parent in reachable: - reachable.add(rev) + reached(rev) return baseset(sorted(reachable)) elements = {