Patchwork [3,of,3,V2] revlog: avoid applying delta chain on cache hit

login
register
mail settings
Submitter Jun Wu
Date April 3, 2017, 1:43 a.m.
Message ID <8324b03f08a91fd039ee.1491183781@x1c>
Download mbox | patch
Permalink /patch/19922/
State Accepted
Headers show

Comments

Jun Wu - April 3, 2017, 1:43 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1491183613 25200
#      Sun Apr 02 18:40:13 2017 -0700
# Node ID 8324b03f08a91fd039ee83428b86792374640b89
# Parent  e5669675e4f24e98c99165c112fa81db66ff6094
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8324b03f08a9
revlog: avoid applying delta chain on cache hit

Previously, revlog.revision(raw=False) may try to apply the delta chain
on _cache hit. That happens if flags are non-empty. This patch makes rawtext
reused so delta chain application is avoided.

"_cache" and "rev" are moved a bit to avoid unnecessary assignments.
Augie Fackler - April 3, 2017, 8:18 p.m.
On Sun, Apr 02, 2017 at 06:43:01PM -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1491183613 25200
> #      Sun Apr 02 18:40:13 2017 -0700
> # Node ID 8324b03f08a91fd039ee83428b86792374640b89
> # Parent  e5669675e4f24e98c99165c112fa81db66ff6094
> # Available At https://bitbucket.org/quark-zju/hg-draft

queued, thanks

> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 8324b03f08a9
> revlog: avoid applying delta chain on cache hit
>
> Previously, revlog.revision(raw=False) may try to apply the delta chain
> on _cache hit. That happens if flags are non-empty. This patch makes rawtext
> reused so delta chain application is avoided.
>
> "_cache" and "rev" are moved a bit to avoid unnecessary assignments.
>
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -1269,4 +1269,5 @@ class revlog(object):
>          cachedrev = None
>          flags = None
> +        rawtext = None
>          if node == nullid:
>              return ""
> @@ -1284,9 +1285,10 @@ class revlog(object):
>                  if flags == REVIDX_DEFAULT_FLAGS:
>                      return self._cache[2]
> +                # rawtext is reusable. need to run flag processor
> +                rawtext = self._cache[2]
>
>              cachedrev = self._cache[1]
>
>          # look up what we need to read
> -        rawtext = None
>          if rawtext is None:
>              if rev is None:
> @@ -1306,6 +1308,9 @@ class revlog(object):
>
>              rawtext = mdiff.patches(rawtext, bins)
> +            self._cache = (node, rev, rawtext)
>
>          if flags is None:
> +            if rev is None:
> +                rev = self.rev(node)
>              flags = self.flags(rev)
>
> @@ -1314,5 +1319,4 @@ class revlog(object):
>              self.checkhash(text, node, rev=rev)
>
> -        self._cache = (node, rev, rawtext)
>          return text
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1269,4 +1269,5 @@  class revlog(object):
         cachedrev = None
         flags = None
+        rawtext = None
         if node == nullid:
             return ""
@@ -1284,9 +1285,10 @@  class revlog(object):
                 if flags == REVIDX_DEFAULT_FLAGS:
                     return self._cache[2]
+                # rawtext is reusable. need to run flag processor
+                rawtext = self._cache[2]
 
             cachedrev = self._cache[1]
 
         # look up what we need to read
-        rawtext = None
         if rawtext is None:
             if rev is None:
@@ -1306,6 +1308,9 @@  class revlog(object):
 
             rawtext = mdiff.patches(rawtext, bins)
+            self._cache = (node, rev, rawtext)
 
         if flags is None:
+            if rev is None:
+                rev = self.rev(node)
             flags = self.flags(rev)
 
@@ -1314,5 +1319,4 @@  class revlog(object):
             self.checkhash(text, node, rev=rev)
 
-        self._cache = (node, rev, rawtext)
         return text