changeset 5680:18a70ae9fb0b

topic: add a basic in-memory cache for topic information Right now reading topic information twice means we uncompress a full revision twice. On a simple `hg topic --age` in my mercurial clone, the total runtime goes from 40s to 10s. Still too slow, but significantly less.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 13 Dec 2020 14:48:28 +0100
parents 843e1df7912f
children 33994d579c81
files CHANGELOG hgext3rd/topic/__init__.py
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG	Tue Dec 01 21:05:53 2020 +0100
+++ b/CHANGELOG	Sun Dec 13 14:48:28 2020 +0100
@@ -6,6 +6,8 @@
 
   * strip: remove experimental.prunestrip option
 
+  * performance: speed up various operations using an in-memory cache for topic
+
 10.1.0 -- 2020-10-31
 --------------------
 
--- a/hgext3rd/topic/__init__.py	Tue Dec 01 21:05:53 2020 +0100
+++ b/hgext3rd/topic/__init__.py	Sun Dec 13 14:48:28 2020 +0100
@@ -294,7 +294,12 @@
 def _contexttopic(self, force=False):
     if not (force or self.mutable()):
         return b''
-    return self.extra().get(constants.extrakey, b'')
+    topic = self._repo._topiccache.get(self.rev())
+    if topic is None:
+        topic = self.extra().get(constants.extrakey, b'')
+        self._repo._topiccache[self.rev()] = topic
+    return topic
+
 context.basectx.topic = _contexttopic
 
 def _contexttopicidx(self):
@@ -481,6 +486,10 @@
                 del ctx.extra()[constants.extrakey]
             return super(topicrepo, self).commitctx(ctx, *args, **kwargs)
 
+        @util.propertycache
+        def _topiccache(self):
+            return {}
+
         @property
         def topics(self):
             if self._topics is not None: