# HG changeset patch # User Pierre-Yves David # Date 1607867308 -3600 # Node ID 18a70ae9fb0bdacdd0e6cd97ee574fa79e7ef07e # Parent 843e1df7912fdb2fcd618007f936259d374043e3 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. diff -r 843e1df7912f -r 18a70ae9fb0b CHANGELOG --- 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 -------------------- diff -r 843e1df7912f -r 18a70ae9fb0b hgext3rd/topic/__init__.py --- 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: