Mercurial > hg-stable
changeset 40492:597bb5a6867f
filecache: use try-except for faster __dict__ lookup
Python function call is slow, and the cost could be significant here.
$ hg perfrevset 'branch(tip)' -R mercurial
(orig) wall 0.139511 comb 0.140000 user 0.140000 sys 0.000000 (best of 66)
(this) wall 0.114195 comb 0.110000 user 0.110000 sys 0.000000 (best of 81)
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 20 Oct 2018 19:13:05 +0900 |
parents | dce0e0f78f0f |
children | 7caf632e30c3 |
files | mercurial/localrepo.py mercurial/scmutil.py |
diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/localrepo.py Thu Oct 18 19:57:30 2018 -0700 +++ b/mercurial/localrepo.py Sat Oct 20 19:13:05 2018 +0900 @@ -91,7 +91,13 @@ def __get__(self, repo, type=None): if repo is None: return self - return super(_basefilecache, self).__get__(repo.unfiltered(), type) + # inlined the fast path as the cost of function call matters + unfi = repo.unfiltered() + try: + return unfi.__dict__[self.sname] + except KeyError: + pass + return super(_basefilecache, self).__get__(unfi, type) def __set__(self, repo, value): return super(_basefilecache, self).__set__(repo.unfiltered(), value) def __delete__(self, repo):
--- a/mercurial/scmutil.py Thu Oct 18 19:57:30 2018 -0700 +++ b/mercurial/scmutil.py Sat Oct 20 19:13:05 2018 +0900 @@ -1292,9 +1292,10 @@ if obj is None: return self # do we need to check if the file changed? - if self.sname in obj.__dict__: - assert self.name in obj._filecache, self.name + try: return obj.__dict__[self.sname] + except KeyError: + pass entry = obj._filecache.get(self.name)