This is an archive of the discontinued Mercurial Phabricator instance.

branchmap: build the revbranchcache._namesreverse() only when required
ClosedPublic

Authored by pulkit on Nov 21 2018, 9:17 AM.

Details

Summary

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().

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

pulkit created this revision.Nov 21 2018, 9:17 AM
yuja added a subscriber: yuja.Nov 21 2018, 9:39 AM

+ if self._namesreverse is None:
+ self._namesreverse = dict((b, r) for r, b in enumerate(self._names))

if b in self._namesreverse:
    branchidx = self._namesreverse[b]
else:

@@ -467,6 +469,8 @@

def setdata(self, branch, rev, node, close):
    """add new data information to the cache"""

+ if self._namesreverse is None:
+ self._namesreverse = dict((b, r) for r, b in enumerate(self._names))

Maybe _namesreverse can be a propertycache, instead of duplicating it.
del self.__dict__[r'...'] can be used to discard the cache.

In D5291#78794, @yuja wrote:

+ if self._namesreverse is None:
+ self._namesreverse = dict((b, r) for r, b in enumerate(self._names))

if b in self._namesreverse:
    branchidx = self._namesreverse[b]
else:

@@ -467,6 +469,8 @@

def setdata(self, branch, rev, node, close):
    """add new data information to the cache"""

+ if self._namesreverse is None:
+ self._namesreverse = dict((b, r) for r, b in enumerate(self._names))

Maybe _namesreverse can be a propertycache, instead of duplicating it.
del self.__dict__[r'...'] can be used to discard the cache.

Hm, I am not sure if I feel good about doing del self.__dict__[r'...'] thing.

yuja added a comment.Nov 22 2018, 8:32 AM
> Maybe _namesreverse can be a propertycache, instead of duplicating it.
>  `del self.__dict__[r'...']` can be used to discard the cache.
Hm, I am not sure if I feel good about doing `del self.__dict__[r'...']` thing.

It's pretty common in Mercurial codebase. That said, I found a better way.
util.clearcachedproperty(self, '...').

pulkit edited the summary of this revision. (Show Details)Nov 22 2018, 9:00 AM
pulkit updated this revision to Diff 12586.
This revision was automatically updated to reflect the committed changes.