Patchwork D9827: changelog: cache the latest `changelogrevision` access

login
register
mail settings
Submitter phabricator
Date Jan. 18, 2021, 6:11 p.m.
Message ID <differential-rev-PHID-DREV-3cdwdy2acnhgjoy6sqao-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48137/
State New
Headers show

Comments

phabricator - Jan. 18, 2021, 6:11 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will speedup repeated call to the same data. Which can be common when
  warming various cache after adding a revision.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/changelog.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -418,6 +418,8 @@ 
         self._filteredrevs = frozenset()
         self._filteredrevs_hashcache = {}
         self._copiesstorage = opener.options.get(b'copies-storage')
+        self._changelogrevision_cache = None
+        self._changelogrevision_key = None
 
     @property
     def filteredrevs(self):
@@ -521,10 +523,14 @@ 
 
     def changelogrevision(self, nodeorrev):
         """Obtain a ``changelogrevision`` for a node or revision."""
+        if nodeorrev == self._changelogrevision_key:
+            return self._changelogrevision_cache
         text, sidedata = self._revisiondata(nodeorrev)
-        return changelogrevision(
+        cr = changelogrevision(
             text, sidedata, self._copiesstorage == b'changeset-sidedata'
         )
+        self._changelogrevision_cache = cr
+        self._changelogrevision_key = nodeorrev
 
     def readfiles(self, node):
         """