Patchwork [3,of,3] branchmap: do not specify changelog as an argument

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 23, 2018, 12:43 p.m.
Message ID <9dbe2753c9eabb95eda4.1540298608@mimosa>
Download mbox | patch
Permalink /patch/36243/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 23, 2018, 12:43 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1540296673 -32400
#      Tue Oct 23 21:11:13 2018 +0900
# Node ID 9dbe2753c9eabb95eda4cb8be726dd5e29f4cc7a
# Parent  759c7efd7c9132ce6dac5bbd9a37e70acb420d24
branchmap: do not specify changelog as an argument

Since (unfiltered)repo.changelog lookup gets as fast as __dict__ lookup,
there's no point to pass in changelog instance.

  $ hg perfbranchmap --clear-revbranch -R mozilla-central
  ! base
  (orig) wall 20.593091 comb 20.600000 user 20.520000 sys 0.080000 (best of 3)
  (this) wall 20.129126 comb 20.130000 user 20.020000 sys 0.110000 (best of 3)

This backs out most of the changes in 76d4272bd57b and 47c03042cd1d.
Augie Fackler - Oct. 23, 2018, 2:51 p.m.
queued, very nice

> On Oct 23, 2018, at 08:43, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1540296673 -32400
> #      Tue Oct 23 21:11:13 2018 +0900
> # Node ID 9dbe2753c9eabb95eda4cb8be726dd5e29f4cc7a
> # Parent  759c7efd7c9132ce6dac5bbd9a37e70acb420d24
> branchmap: do not specify changelog as an argument
> 
> Since (unfiltered)repo.changelog lookup gets as fast as __dict__ lookup,
> there's no point to pass in changelog instance.
> 
>  $ hg perfbranchmap --clear-revbranch -R mozilla-central
>  ! base
>  (orig) wall 20.593091 comb 20.600000 user 20.520000 sys 0.080000 (best of 3)
>  (this) wall 20.129126 comb 20.130000 user 20.020000 sys 0.110000 (best of 3)
> 
> This backs out most of the changes in 76d4272bd57b and 47c03042cd1d.
> 
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -281,7 +281,7 @@ class branchcache(dict):
>         newbranches = {}
>         getbranchinfo = repo.revbranchcache().branchinfo
>         for r in revgen:
> -            branch, closesbranch = getbranchinfo(r, changelog=cl)
> +            branch, closesbranch = getbranchinfo(r)
>             newbranches.setdefault(branch, []).append(r)
>             if closesbranch:
>                 self._closednodes.add(cl.node(r))
> @@ -407,10 +407,10 @@ class revbranchcache(object):
>         self._rbcrevslen = len(self._repo.changelog)
>         self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize)
> 
> -    def branchinfo(self, rev, changelog=None):
> +    def branchinfo(self, rev):
>         """Return branch name and close flag for rev, using and updating
>         persistent cache."""
> -        changelog = changelog or self._repo.changelog
> +        changelog = self._repo.changelog
>         rbcrevidx = rev * _rbcrecsize
> 
>         # avoid negative index, changelog.read(nullrev) is fast without cache
> @@ -419,7 +419,7 @@ class revbranchcache(object):
> 
>         # if requested rev isn't allocated, grow and cache the rev info
>         if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
> -            return self._branchinfo(rev, changelog=changelog)
> +            return self._branchinfo(rev)
> 
>         # fast path: extract data from cache, use it if node is matching
>         reponode = changelog.node(rev)[:_rbcnodelen]
> @@ -447,11 +447,11 @@ class revbranchcache(object):
>             self._rbcrevslen = min(self._rbcrevslen, truncate)
> 
>         # fall back to slow path and make sure it will be written to disk
> -        return self._branchinfo(rev, changelog=changelog)
> +        return self._branchinfo(rev)
> 
> -    def _branchinfo(self, rev, changelog=None):
> +    def _branchinfo(self, rev):
>         """Retrieve branch info from changelog and update _rbcrevs"""
> -        changelog = changelog or self._repo.changelog
> +        changelog = self._repo.changelog
>         b, close = changelog.branchinfo(rev)
>         if b in self._namesreverse:
>             branchidx = self._namesreverse[b]
> @@ -462,7 +462,7 @@ class revbranchcache(object):
>         reponode = changelog.node(rev)
>         if close:
>             branchidx |= _rbccloseflag
> -        self._setcachedata(rev, reponode, branchidx, changelog)
> +        self._setcachedata(rev, reponode, branchidx)
>         return b, close
> 
>     def setdata(self, branch, rev, node, close):
> @@ -485,16 +485,14 @@ class revbranchcache(object):
>         if r'branchinfo' in vars(self):
>             del self.branchinfo
> 
> -    def _setcachedata(self, rev, node, branchidx, changelog=None):
> +    def _setcachedata(self, rev, node, branchidx):
>         """Writes the node's branch data to the in-memory cache data."""
>         if rev == nullrev:
>             return
> -
> -        changelog = changelog or self._repo.changelog
>         rbcrevidx = rev * _rbcrecsize
>         if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
>             self._rbcrevs.extend('\0' *
> -                                 (len(changelog) * _rbcrecsize -
> +                                 (len(self._repo.changelog) * _rbcrecsize -
>                                   len(self._rbcrevs)))
>         pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx)
>         self._rbcrevslen = min(self._rbcrevslen, rev)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -281,7 +281,7 @@  class branchcache(dict):
         newbranches = {}
         getbranchinfo = repo.revbranchcache().branchinfo
         for r in revgen:
-            branch, closesbranch = getbranchinfo(r, changelog=cl)
+            branch, closesbranch = getbranchinfo(r)
             newbranches.setdefault(branch, []).append(r)
             if closesbranch:
                 self._closednodes.add(cl.node(r))
@@ -407,10 +407,10 @@  class revbranchcache(object):
         self._rbcrevslen = len(self._repo.changelog)
         self._rbcrevs = bytearray(self._rbcrevslen * _rbcrecsize)
 
-    def branchinfo(self, rev, changelog=None):
+    def branchinfo(self, rev):
         """Return branch name and close flag for rev, using and updating
         persistent cache."""
-        changelog = changelog or self._repo.changelog
+        changelog = self._repo.changelog
         rbcrevidx = rev * _rbcrecsize
 
         # avoid negative index, changelog.read(nullrev) is fast without cache
@@ -419,7 +419,7 @@  class revbranchcache(object):
 
         # if requested rev isn't allocated, grow and cache the rev info
         if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
-            return self._branchinfo(rev, changelog=changelog)
+            return self._branchinfo(rev)
 
         # fast path: extract data from cache, use it if node is matching
         reponode = changelog.node(rev)[:_rbcnodelen]
@@ -447,11 +447,11 @@  class revbranchcache(object):
             self._rbcrevslen = min(self._rbcrevslen, truncate)
 
         # fall back to slow path and make sure it will be written to disk
-        return self._branchinfo(rev, changelog=changelog)
+        return self._branchinfo(rev)
 
-    def _branchinfo(self, rev, changelog=None):
+    def _branchinfo(self, rev):
         """Retrieve branch info from changelog and update _rbcrevs"""
-        changelog = changelog or self._repo.changelog
+        changelog = self._repo.changelog
         b, close = changelog.branchinfo(rev)
         if b in self._namesreverse:
             branchidx = self._namesreverse[b]
@@ -462,7 +462,7 @@  class revbranchcache(object):
         reponode = changelog.node(rev)
         if close:
             branchidx |= _rbccloseflag
-        self._setcachedata(rev, reponode, branchidx, changelog)
+        self._setcachedata(rev, reponode, branchidx)
         return b, close
 
     def setdata(self, branch, rev, node, close):
@@ -485,16 +485,14 @@  class revbranchcache(object):
         if r'branchinfo' in vars(self):
             del self.branchinfo
 
-    def _setcachedata(self, rev, node, branchidx, changelog=None):
+    def _setcachedata(self, rev, node, branchidx):
         """Writes the node's branch data to the in-memory cache data."""
         if rev == nullrev:
             return
-
-        changelog = changelog or self._repo.changelog
         rbcrevidx = rev * _rbcrecsize
         if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
             self._rbcrevs.extend('\0' *
-                                 (len(changelog) * _rbcrecsize -
+                                 (len(self._repo.changelog) * _rbcrecsize -
                                   len(self._rbcrevs)))
         pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx)
         self._rbcrevslen = min(self._rbcrevslen, rev)