[Updated] D9023: branchmap: add a cache validation cache, avoid expensive re-hash on every use

spectral (Kyle Lippincott) phabricator at mercurial-scm.org
Mon Sep 21 20:27:04 UTC 2020


Closed by commit rHG89f0d9f87701: branchmap: add a cache validation cache, avoid expensive re-hash on every use (authored by spectral).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9023?vs=22658&id=22751

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9023/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D9023

AFFECTED FILES
  mercurial/changelog.py
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -364,13 +364,15 @@
     cl = repo.changelog
     if not cl.filteredrevs:
         return None
-    key = None
-    revs = sorted(r for r in cl.filteredrevs if r <= maxrev)
-    if revs:
-        s = hashutil.sha1()
-        for rev in revs:
-            s.update(b'%d;' % rev)
-        key = s.digest()
+    key = cl._filteredrevs_hashcache.get(maxrev)
+    if not key:
+        revs = sorted(r for r in cl.filteredrevs if r <= maxrev)
+        if revs:
+            s = hashutil.sha1()
+            for rev in revs:
+                s.update(b'%d;' % rev)
+            key = s.digest()
+            cl._filteredrevs_hashcache[maxrev] = key
     return key
 
 
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -403,9 +403,21 @@
         self._delayed = False
         self._delaybuf = None
         self._divert = False
-        self.filteredrevs = frozenset()
+        self._filteredrevs = frozenset()
+        self._filteredrevs_hashcache = {}
         self._copiesstorage = opener.options.get(b'copies-storage')
 
+    @property
+    def filteredrevs(self):
+        return self._filteredrevs
+
+    @filteredrevs.setter
+    def filteredrevs(self, val):
+        # Ensure all updates go through this function
+        assert isinstance(val, frozenset)
+        self._filteredrevs = val
+        self._filteredrevs_hashcache = {}
+
     def delayupdate(self, tr):
         """delay visibility of index updates to other readers"""
 



To: spectral, #hg-reviewers, martinvonz
Cc: martinvonz, marmoute, pulkit, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200921/1ed708c1/attachment-0002.html>


More information about the Mercurial-patches mailing list