Mercurial > hg
diff mercurial/localrepo.py @ 40423: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 | 7e3b6c4f01a2 |
children | 7caf632e30c3 |
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):