tags-cache: directly operate on rev-num warming hgtagsfnodescache
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 13 Mar 2024 11:51:11 +0100
changeset 51598 2664cacd2457
parent 51597 b4a6a1ff8fce
child 51599 b0aaffcb6fcf
tags-cache: directly operate on rev-num warming hgtagsfnodescache Not having to goes through nodeid speed up things notably. ### data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog # benchmark.name = hg.debug.debug-update-cache # bin-env-vars.hg.flavor = default # bin-env-vars.hg.py-re2-module = default # benchmark.variants.pre-state = warm before-this-series: 19.947581 before-this-changes: 18.916804 (-5.17%, -1.03) this-changesets: 17.493725 (-12.30%, -2.45)
mercurial/tags.py
--- a/mercurial/tags.py	Wed Mar 13 11:38:28 2024 +0100
+++ b/mercurial/tags.py	Wed Mar 13 11:51:11 2024 +0100
@@ -83,9 +83,7 @@
 def warm_cache(repo):
     """ensure the cache is properly filled"""
     unfi = repo.unfiltered()
-    tonode = unfi.changelog.node
-    nodes = [tonode(r) for r in unfi.changelog.revs()]
-    _getfnodes(repo.ui, repo, nodes)
+    _getfnodes(repo.ui, repo, revs=unfi.changelog.revs())
 
 
 def fnoderevs(ui, repo, revs):
@@ -498,7 +496,7 @@
     return (repoheads, cachefnode, valid, None, True)
 
 
-def _getfnodes(ui, repo, nodes):
+def _getfnodes(ui, repo, nodes=None, revs=None):
     """return .hgtags fnodes for a list of changeset nodes
 
     Return value is a {node: fnode} mapping. There will be no entry for nodes
@@ -510,9 +508,21 @@
     validated_fnodes = set()
     unknown_entries = set()
 
+    if nodes is None and revs is None:
+        raise error.ProgrammingError("need to specify either nodes or revs")
+    elif nodes is not None and revs is None:
+        to_rev = repo.changelog.index.rev
+        nodes_revs = ((n, to_rev(n)) for n in nodes)
+    elif nodes is None and revs is not None:
+        to_node = repo.changelog.node
+        nodes_revs = ((to_node(r), r) for r in revs)
+    else:
+        msg = "need to specify only one of nodes or revs"
+        raise error.ProgrammingError(msg)
+
     flog = None
-    for node in nodes:
-        fnode = fnodescache.getfnode(node)
+    for node, rev in nodes_revs:
+        fnode = fnodescache.getfnode(node=node, rev=rev)
         if fnode != repo.nullid:
             if fnode not in validated_fnodes:
                 if flog is None:
@@ -765,7 +775,7 @@
             # TODO: zero fill entire record, because it's invalid not missing?
             self._raw.extend(b'\xff' * (wantedlen - rawlen))
 
-    def getfnode(self, node, computemissing=True):
+    def getfnode(self, node, computemissing=True, rev=None):
         """Obtain the filenode of the .hgtags file at a specified revision.
 
         If the value is in the cache, the entry will be validated and returned.
@@ -780,7 +790,8 @@
         if node == self._repo.nullid:
             return node
 
-        rev = self._repo.changelog.rev(node)
+        if rev is None:
+            rev = self._repo.changelog.rev(node)
 
         self.lookupcount += 1