tags: avoid expensive access to repo.changelog in a loop stable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 21 Jun 2023 21:57:44 +0200
branchstable
changeset 50942 75d3306fbc9a
parent 50941 4323af38e3f2
child 50984 2dcb6a6c7540
tags: avoid expensive access to repo.changelog in a loop repo.changelog needs some cache invalidation when run on filtered repository. Accessing it in that loop can be expensive when there is many heads (e.g. mozilla try and it 25 000 heads). Note that the loop itself seems useless, but after this patch it no longer take about ⅛ of the time we spend computing cache for mozilla try. before : ! wall 0.350994 comb 0.350000 user 0.330000 sys 0.020000 (median of 28) after : ! wall 0.319520 comb 0.310000 user 0.290000 sys 0.020000 (median of 30)
mercurial/tags.py
--- a/mercurial/tags.py	Thu Jun 22 19:41:26 2023 +0200
+++ b/mercurial/tags.py	Wed Jun 21 21:57:44 2023 +0200
@@ -190,10 +190,9 @@
         _updatetags(cachetags, alltags)
         return alltags
 
+    has_node = repo.changelog.index.has_node
     for head in reversed(heads):  # oldest to newest
-        assert repo.changelog.index.has_node(
-            head
-        ), b"tag cache returned bogus head %s" % short(head)
+        assert has_node(head), b"tag cache returned bogus head %s" % short(head)
     fnodes = _filterfnodes(tagfnode, reversed(heads))
     alltags = _tagsfromfnodes(ui, repo, fnodes)