changegroup: cache changelog and manifestlog outside of loop
authorGregory Szorc <gregory.szorc@gmail.com>
Tue, 01 Nov 2016 18:28:03 -0700
changeset 30267 d92777f98524
parent 30266 730c7fc8889a
child 30268 dc7c4dbc1af9
changegroup: cache changelog and manifestlog outside of loop History has taught us that repo.changelog can add significant overhead to loops. So cache the changelog instance outside of the loop to avoid the lookup. While we're here, do the same for manifestlog, since each loop would otherwise initialize a new manifestlog instance.
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Tue Nov 01 18:49:23 2016 -0700
+++ b/mercurial/changegroup.py	Tue Nov 01 18:28:03 2016 -0700
@@ -330,11 +330,12 @@
 
                 needfiles = {}
                 if repo.ui.configbool('server', 'validate', default=False):
+                    cl = repo.changelog
+                    ml = repo.manifestlog
                     # validate incoming csets have their manifests
                     for cset in xrange(clstart, clend):
-                        mfnode = repo.changelog.read(
-                            repo.changelog.node(cset))[0]
-                        mfest = repo.manifestlog[mfnode].readdelta()
+                        mfnode = cl.read(cl.node(cset))[0]
+                        mfest = ml[mfnode].readdelta()
                         # store file nodes we must see
                         for f, n in mfest.iteritems():
                             needfiles.setdefault(f, set()).add(n)