Mercurial > hg
comparison mercurial/discovery.py @ 51594:e3a5ec2d236a
outgoing: rework the handling of the `missingroots` case to be faster
The previous implementation was slow, to the point it was taking a significant
amount of `hg bundle --type none-streamv2` call. We rework the code to compute
the same value much faster, making the operation disappear from the `hg bundle
--type none-streamv2` profile. Someone would remark that producing a streamclone
does not requires an `outgoing` object. However that is a matter for another
day. There is other user of `missingroots` (non stream `hg bundle` call for
example), and they will also benefit from this rework.
We implement an old TODO in the process, directly computing the missing and
common attribute as we have most element at hand already.
### benchmark.name = hg.command.bundle
# bin-env-vars.hg.flavor = default
# bin-env-vars.hg.py-re2-module = default
# benchmark.variants.revs = all
# benchmark.variants.type = none-streamv2
## data-env-vars.name = heptapod-public-2024-03-25-zstd-sparse-revlog
before: 7.750458
after: 6.665565 (-14.00%, -1.08)
## data-env-vars.name = mercurial-public-2024-03-22-zstd-sparse-revlog
before: 0.700229
after: 0.496050 (-29.16%, -0.20)
## data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog
before: 346.508952
after: 316.749699 (-8.59%, -29.76)
## data-env-vars.name = pypy-2024-03-22-zstd-sparse-revlog
before: 3.401700
after: 2.915810 (-14.28%, -0.49)
## data-env-vars.name = tryton-public-2024-03-22-zstd-sparse-revlog
before: 1.870798
after: 1.461583 (-21.87%, -0.41)
note: this whole `missingroots` of outgoing has a limited number of callers and
could likely be replace by something simpler (like taking an explicit
"missing_revs" set for example). However this is a wider change and we focus on
a small impact, quick rework that does not change the API for now.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 09 Apr 2024 22:36:35 +0200 |
parents | b70628a9aa7e |
children | 3a6fae3bef35 |
comparison
equal
deleted
inserted
replaced
51593:b5500857e173 | 51594:e3a5ec2d236a |
---|---|
16 | 16 |
17 from . import ( | 17 from . import ( |
18 bookmarks, | 18 bookmarks, |
19 branchmap, | 19 branchmap, |
20 error, | 20 error, |
21 node as nodemod, | |
21 obsolete, | 22 obsolete, |
22 phases, | 23 phases, |
23 pycompat, | 24 pycompat, |
24 scmutil, | 25 scmutil, |
25 setdiscovery, | 26 setdiscovery, |
96 by discovery.""" | 97 by discovery.""" |
97 | 98 |
98 def __init__( | 99 def __init__( |
99 self, repo, commonheads=None, ancestorsof=None, missingroots=None | 100 self, repo, commonheads=None, ancestorsof=None, missingroots=None |
100 ): | 101 ): |
101 # at least one of them must not be set | 102 # at most one of them must not be set |
102 assert None in (commonheads, missingroots) | 103 if commonheads is not None and missingroots is not None: |
104 m = 'commonheads and missingroots arguments are mutually exclusive' | |
105 raise error.ProgrammingError(m) | |
103 cl = repo.changelog | 106 cl = repo.changelog |
107 missing = None | |
108 common = None | |
104 if ancestorsof is None: | 109 if ancestorsof is None: |
105 ancestorsof = cl.heads() | 110 ancestorsof = cl.heads() |
106 if missingroots: | 111 if missingroots: |
107 # TODO remove call to nodesbetween. | 112 # TODO remove call to nodesbetween. |
108 # TODO populate attributes on outgoing instance instead of setting | 113 missing_rev = repo.revs('%ln::%ln', missingroots, ancestorsof) |
109 # discbases. | 114 unfi = repo.unfiltered() |
110 csets, roots, heads = cl.nodesbetween(missingroots, ancestorsof) | 115 ucl = unfi.changelog |
111 included = set(csets) | 116 to_node = ucl.node |
112 discbases = [] | 117 ancestorsof = [to_node(r) for r in ucl.headrevs(missing_rev)] |
113 for n in csets: | 118 parent_revs = ucl.parentrevs |
114 discbases.extend([p for p in cl.parents(n) if p != repo.nullid]) | 119 common_legs = set() |
115 ancestorsof = heads | 120 for r in missing_rev: |
116 commonheads = [n for n in discbases if n not in included] | 121 p1, p2 = parent_revs(r) |
122 if p1 not in missing_rev: | |
123 common_legs.add(p1) | |
124 if p2 not in missing_rev: | |
125 common_legs.add(p2) | |
126 common_legs.discard(nodemod.nullrev) | |
127 if not common_legs: | |
128 commonheads = [repo.nullid] | |
129 common = set() | |
130 else: | |
131 commonheads_revs = unfi.revs( | |
132 'heads(%ld::%ld)', | |
133 common_legs, | |
134 common_legs, | |
135 ) | |
136 commonheads = [to_node(r) for r in commonheads_revs] | |
137 common = ucl.ancestors(commonheads_revs, inclusive=True) | |
138 missing = [to_node(r) for r in missing_rev] | |
117 elif not commonheads: | 139 elif not commonheads: |
118 commonheads = [repo.nullid] | 140 commonheads = [repo.nullid] |
119 self.commonheads = commonheads | 141 self.commonheads = commonheads |
120 self.ancestorsof = ancestorsof | 142 self.ancestorsof = ancestorsof |
121 self._revlog = cl | 143 self._revlog = cl |
122 self._common = None | 144 self._common = common |
123 self._missing = None | 145 self._missing = missing |
124 self.excluded = [] | 146 self.excluded = [] |
125 | 147 |
126 def _computecommonmissing(self): | 148 def _computecommonmissing(self): |
127 sets = self._revlog.findcommonmissing( | 149 sets = self._revlog.findcommonmissing( |
128 self.commonheads, self.ancestorsof | 150 self.commonheads, self.ancestorsof |