# HG changeset patch # User Pulkit Goyal # Date 2018-11-21 14:17:26 # Node ID 50a64c321c1e74b98ec1fa959bdc92efdc6f4ee7 # Parent 39d29542fe40d79cb8caabdaa2459ed2e47b4e25 branchmap: build the revbranchcache._namesreverse() only when required On big repositories with a lot of named branches and that also increasing over time, building of this dict can be expensive and shows up in profile. For our internal repository, this saves ~0.05 seconds. Thanks to Yuya for suggesting using util.propertycache() and util.clearcachedproperty(). Differential Revision: https://phab.mercurial-scm.org/D5291 diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -397,15 +397,18 @@ class revbranchcache(object): self._names = [] self._rbcnamescount = len(self._names) # number of names read at # _rbcsnameslen - self._namesreverse = dict((b, r) for r, b in enumerate(self._names)) def _clear(self): self._rbcsnameslen = 0 del self._names[:] self._rbcnamescount = 0 - self._namesreverse.clear() self._rbcrevslen = len(self._repo.changelog) self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize) + util.clearcachedproperty(self, '_namesreverse') + + @util.propertycache + def _namesreverse(self): + return dict((b, r) for r, b in enumerate(self._names)) def branchinfo(self, rev): """Return branch name and close flag for rev, using and updating