Patchwork [1,of,2] changegroup: cache changelog and manifestlog outside of loop

login
register
mail settings
Submitter Gregory Szorc
Date Nov. 2, 2016, 1:29 a.m.
Message ID <9cd491f108689228e93b.1478050177@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/17262/
State Accepted
Headers show

Comments

Gregory Szorc - Nov. 2, 2016, 1:29 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1478050083 25200
#      Tue Nov 01 18:28:03 2016 -0700
# Node ID 9cd491f108689228e93b1247772aba56786afcd7
# Parent  e5cc44ea12de681d971fcbebb65a7fb71fd1c3c7
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.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -330,11 +330,12 @@  class cg1unpacker(object):
 
                 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)