Mercurial > hg
comparison mercurial/revset.py @ 25191:08d1ef09ed37
revset: optimize not public revset
This patvh speeds up the computation of the not public() changeset
and incidentally speed up the computation of divergents() changeset on our big
repo by 100x from 50% to 0.5% of the time spent in smartlog with evolve.
In this patch we optimize not public() to _notpublic() (new revset) and use
the work on phaseset (from the previous commit) to be able to compute
_notpublic() quickly.
We use a non-lazy approach making the assumption the number of notpublic
change will not be in the order of magnitude of the repo size. Adopting a
lazy approach gives a speedup of 5x (vs 100x) only due to the overhead of the
code for lazy generation.
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Fri, 24 Apr 2015 14:30:30 -0700 |
parents | 3f0744eeaeaf |
children | d032f57936f5 |
comparison
equal
deleted
inserted
replaced
25190:22438cfd11b5 | 25191:08d1ef09ed37 |
---|---|
1476 try: | 1476 try: |
1477 return getset(repo, subset, x) | 1477 return getset(repo, subset, x) |
1478 except error.RepoLookupError: | 1478 except error.RepoLookupError: |
1479 return baseset() | 1479 return baseset() |
1480 | 1480 |
1481 def _notpublic(repo, subset, x): | |
1482 """``_notpublic()`` | |
1483 Changeset not in public phase.""" | |
1484 # i18n: "public" is a keyword | |
1485 getargs(x, 0, 0, _("_notpublic takes no arguments")) | |
1486 if repo._phasecache._phasesets: | |
1487 s = set() | |
1488 for u in repo._phasecache._phasesets[1:]: | |
1489 s.update(u) | |
1490 return subset & s | |
1491 else: | |
1492 phase = repo._phasecache.phase | |
1493 target = phases.public | |
1494 condition = lambda r: phase(repo, r) != target | |
1495 return subset.filter(condition, cache=False) | |
1496 | |
1481 def public(repo, subset, x): | 1497 def public(repo, subset, x): |
1482 """``public()`` | 1498 """``public()`` |
1483 Changeset in public phase.""" | 1499 Changeset in public phase.""" |
1484 # i18n: "public" is a keyword | 1500 # i18n: "public" is a keyword |
1485 getargs(x, 0, 0, _("public takes no arguments")) | 1501 getargs(x, 0, 0, _("public takes no arguments")) |
1982 "p1": p1, | 1998 "p1": p1, |
1983 "p2": p2, | 1999 "p2": p2, |
1984 "parents": parents, | 2000 "parents": parents, |
1985 "present": present, | 2001 "present": present, |
1986 "public": public, | 2002 "public": public, |
2003 "_notpublic": _notpublic, | |
1987 "remote": remote, | 2004 "remote": remote, |
1988 "removes": removes, | 2005 "removes": removes, |
1989 "rev": rev, | 2006 "rev": rev, |
1990 "reverse": reverse, | 2007 "reverse": reverse, |
1991 "roots": roots, | 2008 "roots": roots, |
2056 "p1", | 2073 "p1", |
2057 "p2", | 2074 "p2", |
2058 "parents", | 2075 "parents", |
2059 "present", | 2076 "present", |
2060 "public", | 2077 "public", |
2078 "_notpublic", | |
2061 "remote", | 2079 "remote", |
2062 "removes", | 2080 "removes", |
2063 "rev", | 2081 "rev", |
2064 "reverse", | 2082 "reverse", |
2065 "roots", | 2083 "roots", |
2147 wb, tb = optimize(x[2], False) | 2165 wb, tb = optimize(x[2], False) |
2148 if wb < wa: | 2166 if wb < wa: |
2149 wb, wa = wa, wb | 2167 wb, wa = wa, wb |
2150 return max(wa, wb), (op, ta, tb) | 2168 return max(wa, wb), (op, ta, tb) |
2151 elif op == 'not': | 2169 elif op == 'not': |
2152 o = optimize(x[1], not small) | 2170 # Optimize not public() to _notpublic() because we have a fast version |
2153 return o[0], (op, o[1]) | 2171 if x[1] == ('func', ('symbol', 'public'), None): |
2172 newsym = ('func', ('symbol', '_notpublic'), None) | |
2173 o = optimize(newsym, not small) | |
2174 return o[0], o[1] | |
2175 else: | |
2176 o = optimize(x[1], not small) | |
2177 return o[0], (op, o[1]) | |
2154 elif op == 'parentpost': | 2178 elif op == 'parentpost': |
2155 o = optimize(x[1], small) | 2179 o = optimize(x[1], small) |
2156 return o[0], (op, o[1]) | 2180 return o[0], (op, o[1]) |
2157 elif op == 'group': | 2181 elif op == 'group': |
2158 return optimize(x[1], small) | 2182 return optimize(x[1], small) |