Mercurial > public > mercurial-scm > evolve
diff hgext3rd/topic/__init__.py @ 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 | 4c1eb455259f |
children | 7ee15bf011d6 |
line wrap: on
line diff
--- 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: