##// END OF EJS Templates
branchmap-v3: filter topo heads using node for performance reason...
branchmap-v3: filter topo heads using node for performance reason The branchmap currently contains heads as nodeid. If we build a set of revnum with the topological heads, we need to turn the nodeid in the branchmap to revnum to be able to check if they are topo-heads. That nodeid → revnum lookup is "expensive" and adds up to something noticeable if you do it hundreds of thousand of time. Instead we turn all the topo-heads revnums into nodes and build a set. So we can directly test membership of the nodeids stored in the branchmap. That is much faster. Ideally we would have revnum in the branchmap and could directly test revnum against a revnum set and that would be even faster. However that's an adventure for another time. Without this change, the branchmap format "v3" was significantly slower than the "v2" format. With this changes, some of that gap is recovered With rust + persistent nodemap, this overhead was smaller because the extra lookup did not had to to build the nodemap from scratch. In addition the mozilla-unified repository is able to use the "pure_top" mode of branchmap v3, so it was not really affected by this. Future changeset will work of the remaining of the performance gap. ### benchmark.name = hg.command.unbundle # bin-env-vars.hg.py-re2-module = default # benchmark.variants.issue6528 = disabled # benchmark.variants.resource-usage = default # benchmark.variants.reuse-external-delta-parent = yes # benchmark.variants.revs = any-1-extra-rev # benchmark.variants.source = unbundle # benchmark.variants.validate = default # benchmark.variants.verbosity = quiet ## data-env-vars.name = netbeans-2018-08-01-zstd-sparse-revlog # bin-env-vars.hg.flavor = default branch-v2: 0.233711 ~~~~~ branch-v3 before: 0.380994 (+63.02%, +0.15) branch-v3 after: 0.368769 (+57.79%, +0.14) # bin-env-vars.hg.flavor = rust branch-v2: 0.235230 ~~~~~ branch-v3 before: 0.385060 (+63.70%, +0.15) branch-v3 after: 0.372460 (+58.34%, +0.14) ## data-env-vars.name = netbeans-2018-08-01-ds2-pnm # bin-env-vars.hg.flavor = rust branch-v2: 0.255586 ~~~~~ branch-v3 before: 0.317524 (+24.23%, +0.06) branch-v3 after: 0.318907 (+24.78%, +0.06) ## data-env-vars.name = mozilla-central-2024-03-22-zstd-sparse-revlog # bin-env-vars.hg.flavor = default branch-v2: 0.339010 ~~~~~ branch-v3 before: 0.410007 (+20.94%, +0.07) branch-v3 after: 0.349752 (+3.17%, +0.01) # bin-env-vars.hg.flavor = rust branch-v2: 0.346525 ~~~~~ branch-v3 before: 0.410428 (+18.44%, +0.06) branch-v3 after: 0.354300 (+2.24%, +0.01) ## data-env-vars.name = mozilla-central-2024-03-22-ds2-pnm # bin-env-vars.hg.flavor = rust branch-v2: 0.380202 ~~~~~ branch-v3 before: 0.393871 (+3.60%, +0.01) branch-v3 after: 0.396293 (+4.23%, +0.02) ## data-env-vars.name = mozilla-unified-2024-03-22-zstd-sparse-revlog # bin-env-vars.hg.flavor = default branch-v2: 0.412165 ~~~~~ branch-v3 before: 0.438105 (+6.29%, +0.03) branch-v3 after: 0.424769 (+3.06%, +0.01) # bin-env-vars.hg.flavor = rust branch-v2: 0.412397 ~~~~~ branch-v3 before: 0.438405 (+6.31%, +0.03) branch-v3 after: 0.421796 (+2.28%, +0.01) ## data-env-vars.name = mozilla-unified-2024-03-22-ds2-pnm # bin-env-vars.hg.flavor = rust branch-v2: 0.429501 ~~~~~ branch-v3 before: 0.452692 (+5.40%, +0.02) branch-v3 after: 0.443849 (+3.34%, +0.01) ## data-env-vars.name = mozilla-try-2024-03-26-zstd-sparse-revlog # bin-env-vars.hg.flavor = default branch-v2: 3.403171 ~~~~~ branch-v3 before: 6.562345 (+92.83%, +3.16) branch-v3 after: 6.234055 (+83.18%, +2.83) # bin-env-vars.hg.flavor = rust branch-v2: 3.454876 ~~~~~ branch-v3 before: 6.160248 (+78.31%, +2.71) branch-v3 after: 6.307813 (+82.58%, +2.85) ## data-env-vars.name = mozilla-try-2024-03-26-ds2-pnm # bin-env-vars.hg.flavor = rust branch-v2: 3.465435 ~~~~~ branch-v3 before: 5.381648 (+55.30%, +1.92) branch-v3 after: 5.176076 (+49.36%, +1.71)

File last commit:

r52862:22da1dc9 default
r52869:41b8892a default
Show More
revlogv0.py
156 lines | 4.2 KiB | text/x-python | PythonLexer
# revlogv0 - code related to revlog format "V0"
#
# Copyright 2005-2007 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import annotations
from ..node import sha1nodeconstants
from .constants import (
INDEX_ENTRY_V0,
)
from ..i18n import _
from .. import (
error,
node,
revlogutils,
util,
)
from . import (
nodemap as nodemaputil,
)
def getoffset(q):
return int(q >> 16)
def gettype(q):
return int(q & 0xFFFF)
class revlogoldindex(list):
rust_ext_compat = 0
entry_size = INDEX_ENTRY_V0.size
null_item = revlogutils.entry(
data_offset=0,
data_compressed_length=0,
data_delta_base=node.nullrev,
link_rev=node.nullrev,
parent_rev_1=node.nullrev,
parent_rev_2=node.nullrev,
node_id=sha1nodeconstants.nullid,
)
@util.propertycache
def _nodemap(self):
nodemap = nodemaputil.NodeMap({sha1nodeconstants.nullid: node.nullrev})
for r in range(0, len(self)):
n = self[r][7]
nodemap[n] = r
return nodemap
def has_node(self, node):
"""return True if the node exist in the index"""
return node in self._nodemap
def rev(self, node):
"""return a revision for a node
If the node is unknown, raise a RevlogError"""
return self._nodemap[node]
def get_rev(self, node):
"""return a revision for a node
If the node is unknown, return None"""
return self._nodemap.get(node)
def append(self, tup):
self._nodemap[tup[7]] = len(self)
super(revlogoldindex, self).append(tup)
def __delitem__(self, i):
if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
raise ValueError(b"deleting slices only supports a:-1 with step 1")
for r in range(i.start, len(self)):
del self._nodemap[self[r][7]]
super(revlogoldindex, self).__delitem__(i)
def clearcaches(self):
self.__dict__.pop('_nodemap', None)
def __getitem__(self, i):
if i == -1:
return self.null_item
return list.__getitem__(self, i)
def pack_header(self, header):
"""pack header information in binary"""
return b''
def entry_binary(self, rev):
"""return the raw binary string representing a revision"""
entry = self[rev]
if gettype(entry[0]):
raise error.RevlogError(
_(b'index entry flags need revlog version 1')
)
e2 = (
getoffset(entry[0]),
entry[1],
entry[3],
entry[4],
self[entry[5]][7],
self[entry[6]][7],
entry[7],
)
return INDEX_ENTRY_V0.pack(*e2)
def headrevs(self, excluded_revs=None):
count = len(self)
if not count:
return [node.nullrev]
# we won't iter over filtered rev so nobody is a head at start
ishead = [0] * (count + 1)
revs = range(count)
if excluded_revs is not None:
revs = (r for r in revs if r not in excluded_revs)
for r in revs:
ishead[r] = 1 # I may be an head
e = self[r]
ishead[e[5]] = ishead[e[6]] = 0 # my parent are not
return [r for r, val in enumerate(ishead) if val]
def parse_index_v0(data, inline):
s = INDEX_ENTRY_V0.size
index = []
nodemap = nodemaputil.NodeMap({node.nullid: node.nullrev})
n = off = 0
l = len(data)
while off + s <= l:
cur = data[off : off + s]
off += s
e = INDEX_ENTRY_V0.unpack(cur)
# transform to revlogv1 format
e2 = revlogutils.entry(
data_offset=e[0],
data_compressed_length=e[1],
data_delta_base=e[2],
link_rev=e[3],
parent_rev_1=nodemap.get(e[4], node.nullrev),
parent_rev_2=nodemap.get(e[5], node.nullrev),
node_id=e[6],
)
index.append(e2)
nodemap[e[6]] = n
n += 1
index = revlogoldindex(index)
return index, None