Patchwork [2,of,3] revlog: prevent multiple `any()` if we are not changing sidedata

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 10, 2020, 8:47 a.m.
Message ID <911cea33820c98da3fa2.1602319643@workspace>
Download mbox | patch
Permalink /patch/47434/
State Accepted
Headers show

Comments

Pulkit Goyal - Oct. 10, 2020, 8:47 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1602159272 -19800
#      Thu Oct 08 17:44:32 2020 +0530
# Node ID 911cea33820c98da3fa2e4891153e674600df1af
# Parent  3fb44ab16f68b2f76a752e873cce80d45fec442f
# EXP-Topic sidedata-upgrade
revlog: prevent multiple `any()` if we are not changing sidedata

For each rev, we check whether there are sidedata related changes or not. We do
so by calling `any()` on a tuple which contains a boolean, a tuple or list and a
dict.

When `sidedatacompanion` is None, we know this `any()` is going to return False,
so let's prevent that.

Patch is motivated by reading the code and trying to fix something else and I
don't have performance numbers as motivation for this patch.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2770,6 +2770,7 @@  class revlog(object):
         sidedatacompanion,
     ):
         """perform the core duty of `revlog.clone` after parameter processing"""
+        sidedatachanges = sidedatacompanion is not None
         deltacomputer = deltautil.deltacomputer(destrevlog)
         index = self.index
         for rev in self:
@@ -2784,14 +2785,16 @@  class revlog(object):
             node = entry[7]
 
             sidedataactions = (False, [], {})
-            if sidedatacompanion is not None:
+            if sidedatachanges:
                 sidedataactions = sidedatacompanion(self, rev)
 
             # (Possibly) reuse the delta from the revlog if allowed and
             # the revlog chunk is a delta.
             cachedelta = None
             rawtext = None
-            if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD:
+            if (
+                sidedatachanges and any(sidedataactions)
+            ) or deltareuse == self.DELTAREUSEFULLADD:
                 dropall, filterout, update = sidedataactions
                 text, sidedata = self._revisiondata(rev)
                 if dropall: