[PATCH 5 of 6 V2] obsstore: prefetch struct.calcsize

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Dec 4 09:16:18 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1417072880 28800
#      Wed Nov 26 23:21:20 2014 -0800
# Node ID 786d60c87bc62b1e5ce5c479d9ebc3973f6b3fa3
# Parent  dcf878af15d0eb3a7997331faac73a0fa5ca736b
obsstore: prefetch struct.calcsize

This function is widely used and worth but be at module level. No specific
performance boost is visible, but this is more consistent.

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -72,10 +72,11 @@ import util, base85, node
 import phases
 from i18n import _
 
 _pack = struct.pack
 _unpack = struct.unpack
+_calcsize = struct.calcsize
 
 _SEEK_END = 2 # os.SEEK_END was introduced in Python 2.5
 
 # the obsolete feature is not mature enough to be enabled by default.
 # you have to rely on third party extension extension to enable this.
@@ -140,12 +141,12 @@ usingsha256 = 2
 #   additional encoding. Keys cannot contain '\0' or ':' and values
 #   cannot contain '\0'.
 _fm0version = 0
 _fm0fixed   = '>BIB20s'
 _fm0node = '20s'
-_fm0fsize = struct.calcsize(_fm0fixed)
-_fm0fnodesize = struct.calcsize(_fm0node)
+_fm0fsize = _calcsize(_fm0fixed)
+_fm0fnodesize = _calcsize(_fm0node)
 
 def _fm0readmarkers(data, off=0):
     # Loop on markers
     l = len(data)
     while off + _fm0fsize <= l:
@@ -273,16 +274,16 @@ def _fm0decodemeta(data):
 # - remaining bytes: the metadata, each (key, value) pair after the other.
 _fm1version = 1
 _fm1fixed = '>IdhHBBB20s'
 _fm1nodesha1 = '20s'
 _fm1nodesha256 = '32s'
-_fm1fsize = struct.calcsize(_fm1fixed)
+_fm1fsize = _calcsize(_fm1fixed)
 _fm1parentnone = 3
 _fm1parentshift = 14
 _fm1parentmask = (_fm1parentnone << _fm1parentshift)
 _fm1metapair = 'BB'
-_fm1metapairsize = struct.calcsize('BB')
+_fm1metapairsize = _calcsize('BB')
 
 def _fm1readmarkers(data, off=0):
     # Loop on markers
     l = len(data)
     while off + _fm1fsize <= l:
@@ -297,11 +298,11 @@ def _fm1readmarkers(data, off=0):
         # build the date tuple (upgrade tz minutes to seconds)
         date = (seconds, tz * 60)
         _fm1node = _fm1nodesha1
         if flags & usingsha256:
             _fm1node = _fm1nodesha256
-        fnodesize = struct.calcsize(_fm1node)
+        fnodesize = _calcsize(_fm1node)
         # read replacement
         sucs = ()
         if numsuc:
             s = (fnodesize * numsuc)
             cur = data[off:off + s]
@@ -356,11 +357,11 @@ def _fm1encodeonemarker(marker):
     tz = date[1]//60
     data = [None, date[0], tz, flags, numsuc, numpar, len(metadata), pre]
     data.extend(sucs)
     if parents is not None:
         data.extend(parents)
-    totalsize = struct.calcsize(format)
+    totalsize = _calcsize(format)
     for key, value in metadata:
         lk = len(key)
         lv = len(value)
         data.append(lk)
         data.append(lv)


More information about the Mercurial-devel mailing list