Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 27907:e219dbfd0342
localrepo: don't reference transaction from hook closure (issue5043)
Before, the hook() closure (which is called as part of locking hooks)
would maintain a reference to a transaction instance (which should be
finalized by the time lock hooks are called). Because we accumulate
hook() instances when there are multiple transactions per lock, this
would result in holding references to the transaction instances which
would lead to higher memory utilization.
Creating a reference to the hook arguments dict minimizes the number
of objects that are kept alive until the lock release hook runs,
minimizing memory "leaks."
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sun, 17 Jan 2016 14:14:15 -0800 |
parents | 63821023ea79 |
children | 3784d9eb7245 |
comparison
equal
deleted
inserted
replaced
27906:c183f7b79541 | 27907:e219dbfd0342 |
---|---|
1083 # this is not expected to break anything that happen during the hooks. | 1083 # this is not expected to break anything that happen during the hooks. |
1084 tr.addfinalize('flush-fncache', self.store.write) | 1084 tr.addfinalize('flush-fncache', self.store.write) |
1085 def txnclosehook(tr2): | 1085 def txnclosehook(tr2): |
1086 """To be run if transaction is successful, will schedule a hook run | 1086 """To be run if transaction is successful, will schedule a hook run |
1087 """ | 1087 """ |
1088 # Don't reference tr2 in hook() so we don't hold a reference. | |
1089 # This reduces memory consumption when there are multiple | |
1090 # transactions per lock. This can likely go away if issue5045 | |
1091 # fixes the function accumulation. | |
1092 hookargs = tr2.hookargs | |
1093 | |
1088 def hook(): | 1094 def hook(): |
1089 reporef().hook('txnclose', throw=False, txnname=desc, | 1095 reporef().hook('txnclose', throw=False, txnname=desc, |
1090 **tr2.hookargs) | 1096 **hookargs) |
1091 reporef()._afterlock(hook) | 1097 reporef()._afterlock(hook) |
1092 tr.addfinalize('txnclose-hook', txnclosehook) | 1098 tr.addfinalize('txnclose-hook', txnclosehook) |
1093 def txnaborthook(tr2): | 1099 def txnaborthook(tr2): |
1094 """To be run if transaction is aborted | 1100 """To be run if transaction is aborted |
1095 """ | 1101 """ |