Patchwork [2,of,3,v4] branchmap: use revbranchcache when updating branch map

login
register
mail settings
Submitter Mads Kiilerich
Date Jan. 9, 2015, 4:03 p.m.
Message ID <1885dd81dd140a9c56b9.1420819439@ssl.google-analytics.com>
Download mbox | patch
Permalink /patch/7401/
State Accepted
Commit 7d63398fbfd1b3f8693e46035c9058b6cfb824aa
Headers show

Comments

Mads Kiilerich - Jan. 9, 2015, 4:03 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1420671663 -3600
#      Thu Jan 08 00:01:03 2015 +0100
# Node ID 1885dd81dd140a9c56b94dd3af811cc040d07a54
# Parent  388a25e2964fba5be3e278628c99b325c5cbbafd
branchmap: use revbranchcache when updating branch map

The revbranchcache is read on demand before it will be used for updating the
branch map. It is written back when the branchmap is written and it will thus
use the same locking as branchmap. The revbranchcache instance is short-lived;
it is only stored in the branchmap from .update() is invoked and until .write()
is invoked. Branchmap already assume that the repo is locked in that case.

The use of revbranchcache for branch map updates will make sure that the
revbranchcache "always" is kept up-to-date.

The perfbranchmap benchmark is somewhat bogus, especially when we can see that
the caching makes a significant difference between the realistic case of a
first run and the rare case of rerunning it with a full cache. Here are some
'base' numbers on mozilla-central:
Before:
! wall 6.912745 comb 6.910000 user 6.840000 sys 0.070000 (best of 3)
After - initial, cache is empty:
! wall 7.792569 comb 7.790000 user 7.720000 sys 0.070000 (best of 3)
After - cache is full:
! wall 0.879688 comb 0.880000 user 0.870000 sys 0.010000 (best of 4)

The overhead when running with empty cache comes from checking, missing and
updating it every time.

Most of the performance improvement comes from not having to extract the branch
info from the changelog. The last doubling of performance comes from no longer
having to convert all branch names to local encoding but reuse the few already
converted branch names.

On the hg repo:
Before:
! wall 0.715703 comb 0.710000 user 0.710000 sys 0.000000 (best of 14)
After:
! wall 0.105489 comb 0.110000 user 0.110000 sys 0.000000 (best of 87)
Mads Kiilerich - Jan. 10, 2015, 12:26 a.m.
On 01/09/2015 05:03 PM, Mads Kiilerich wrote:
> @@ -361,7 +368,7 @@ class revbranchcache(object):
>               self._rbcrevs.extend('\0' * (len(changelog) * _rbcrecsize -
>                                            len(self._rbcrevs)))
>               for r in xrange(first, len(changelog)):
> -                self._branchinfo(r)
> +                self._branchinfo(changelog, r)
>   
>           # fast path: extract data from cache, use it if node is matching
>           reponode = changelog.node(rev)[:_rbcnodelen]
> @@ -374,7 +381,7 @@ class revbranchcache(object):
>               return self._names[branchidx], close
>           # fall back to slow path and make sure it will be written to disk
>           self._rbcrevslen = min(self._rbcrevslen, rev)
> -        return self._branchinfo(rev)
> +        return self._branchinfo(changelog, rev)
>   
>       def _branchinfo(self, changelog, rev):
>           """Retrieve branch info from changelog and update _rbcrevs"""

Oops, these should have been in the previous patch - sorry.

Thanks for reviewing and pushing.

Given this baseline, which next steps would you suggest?

/Mads

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -134,6 +134,7 @@  class branchcache(dict):
             self._closednodes = set()
         else:
             self._closednodes = closednodes
+        self._revbranchcache = None
 
     def _hashfiltered(self, repo):
         """build hash of revision filtered in the current cache
@@ -225,6 +226,9 @@  class branchcache(dict):
             repo.ui.debug("couldn't write branch cache: %s\n" % inst)
             # Abort may be raise by read only opener
             pass
+        if self._revbranchcache:
+            self._revbranchcache.write(repo.unfiltered())
+            self._revbranchcache = None
 
     def update(self, repo, revgen):
         """Given a branchhead cache, self, that may have extra nodes or be
@@ -235,9 +239,12 @@  class branchcache(dict):
         cl = repo.changelog
         # collect new branch entries
         newbranches = {}
-        getbranchinfo = cl.branchinfo
+        urepo = repo.unfiltered()
+        self._revbranchcache = revbranchcache(urepo)
+        getbranchinfo = self._revbranchcache.branchinfo
+        ucl = urepo.changelog
         for r in revgen:
-            branch, closesbranch = getbranchinfo(r)
+            branch, closesbranch = getbranchinfo(ucl, r)
             newbranches.setdefault(branch, []).append(r)
             if closesbranch:
                 self._closednodes.add(cl.node(r))
@@ -361,7 +368,7 @@  class revbranchcache(object):
             self._rbcrevs.extend('\0' * (len(changelog) * _rbcrecsize -
                                          len(self._rbcrevs)))
             for r in xrange(first, len(changelog)):
-                self._branchinfo(r)
+                self._branchinfo(changelog, r)
 
         # fast path: extract data from cache, use it if node is matching
         reponode = changelog.node(rev)[:_rbcnodelen]
@@ -374,7 +381,7 @@  class revbranchcache(object):
             return self._names[branchidx], close
         # fall back to slow path and make sure it will be written to disk
         self._rbcrevslen = min(self._rbcrevslen, rev)
-        return self._branchinfo(rev)
+        return self._branchinfo(changelog, rev)
 
     def _branchinfo(self, changelog, rev):
         """Retrieve branch info from changelog and update _rbcrevs"""
diff --git a/tests/test-clone.t b/tests/test-clone.t
--- a/tests/test-clone.t
+++ b/tests/test-clone.t
@@ -31,6 +31,8 @@  Trigger branchcache creation:
   default                       10:a7949464abda
   $ ls .hg/cache
   branch2-served
+  rbc-names-v1
+  rbc-revs-v1
 
 Default operation:
 
diff --git a/tests/test-convert-svn-encoding.t b/tests/test-convert-svn-encoding.t
--- a/tests/test-convert-svn-encoding.t
+++ b/tests/test-convert-svn-encoding.t
@@ -53,6 +53,7 @@  Convert while testing all possible outpu
   source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@1
   converting: 0/6 revisions (0.00%)
   committing changelog
+  couldn't read revision branch cache names: * (glob)
   4 hello
   source: svn:afeb9c47-92ff-4c0c-9f72-e1f6eb8ac9af/trunk@2
   converting: 1/6 revisions (16.67%)
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -71,6 +71,8 @@  Non store repo:
   .hg/00manifest.i
   .hg/cache
   .hg/cache/branch2-served
+  .hg/cache/rbc-names-v1
+  .hg/cache/rbc-revs-v1
   .hg/data
   .hg/data/tst.d.hg
   .hg/data/tst.d.hg/foo.i
@@ -99,6 +101,8 @@  Non fncache repo:
   .hg/00changelog.i
   .hg/cache
   .hg/cache/branch2-served
+  .hg/cache/rbc-names-v1
+  .hg/cache/rbc-revs-v1
   .hg/dirstate
   .hg/last-message.txt
   .hg/requires
diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t
--- a/tests/test-hardlinks.t
+++ b/tests/test-hardlinks.t
@@ -196,6 +196,8 @@  r4 has hardlinks in the working dir (not
   2 r4/.hg/00changelog.i
   2 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
+  2 r4/.hg/cache/rbc-names-v1
+  2 r4/.hg/cache/rbc-revs-v1
   2 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
@@ -226,6 +228,8 @@  Update back to revision 11 in r4 should 
   2 r4/.hg/00changelog.i
   1 r4/.hg/branch
   2 r4/.hg/cache/branch2-served
+  2 r4/.hg/cache/rbc-names-v1
+  2 r4/.hg/cache/rbc-revs-v1
   1 r4/.hg/dirstate
   2 r4/.hg/hgrc
   2 r4/.hg/last-message.txt
diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t
--- a/tests/test-inherit-mode.t
+++ b/tests/test-inherit-mode.t
@@ -66,6 +66,8 @@  new directories are setgid
   00600 ./.hg/00changelog.i
   00770 ./.hg/cache/
   00660 ./.hg/cache/branch2-served
+  00660 ./.hg/cache/rbc-names-v1
+  00660 ./.hg/cache/rbc-revs-v1
   00660 ./.hg/dirstate
   00660 ./.hg/last-message.txt
   00600 ./.hg/requires
@@ -111,6 +113,8 @@  group can still write everything
   00660 ../push/.hg/00changelog.i
   00770 ../push/.hg/cache/
   00660 ../push/.hg/cache/branch2-base
+  00660 ../push/.hg/cache/rbc-names-v1
+  00660 ../push/.hg/cache/rbc-revs-v1
   00660 ../push/.hg/requires
   00770 ../push/.hg/store/
   00660 ../push/.hg/store/00changelog.i