[PATCH 5 of 8 V3] revlog: use the native implementation of issnapshot

Boris Feld boris.feld at octobus.net
Fri Dec 28 13:12:51 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1545366458 -3600
#      Fri Dec 21 05:27:38 2018 +0100
# Node ID da893aea43102eae6ce8324b8f7667cf90690d1e
# Parent  1ab85bafd017062237be01429bc3ce48ee3ef796
# EXP-Topic sparse-revlog
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r da893aea4310
revlog: use the native implementation of issnapshot

In some sparserevlog case where a lot of the history has to be searched for a
snapshot, the cost of issnashot cost becomes significant. The computation done
by the method is fairly low level, a native implementation provide a very
significant speedup.

example affected manifest write
before: 0.490375s
after:  0.114989s (-76%)

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1028,6 +1028,27 @@ static int index_issnapshotrev(indexObje
 	return rev == -1;
 }
 
+static PyObject *index_issnapshot(indexObject *self, PyObject *value)
+{
+	long rev;
+	int issnap;
+	Py_ssize_t length = index_length(self);
+
+	if (!pylong_to_long(value, &rev)) {
+		return NULL;
+	}
+	if (rev < -1 || rev >= length) {
+		PyErr_Format(PyExc_ValueError, "revlog index out of range: %ld",
+		             rev);
+		return NULL;
+	};
+	issnap = index_issnapshotrev(self, (Py_ssize_t)rev);
+	if (issnap < 0) {
+		return NULL;
+	};
+	return PyBool_FromLong((long)issnap);
+}
+
 static PyObject *index_deltachain(indexObject *self, PyObject *args)
 {
 	int rev, generaldelta;
@@ -2640,6 +2661,8 @@ static PyMethodDef index_methods[] = {
      "get head revisions"}, /* Can do filtering since 3.2 */
     {"headrevsfiltered", (PyCFunction)index_headrevs, METH_VARARGS,
      "get filtered head revisions"}, /* Can always do filtering */
+    {"issnapshot", (PyCFunction)index_issnapshot, METH_O,
+     "True if the object is a snapshot"},
     {"deltachain", (PyCFunction)index_deltachain, METH_VARARGS,
      "determine revisions with deltas to reconstruct fulltext"},
     {"slicechunktodensity", (PyCFunction)index_slicechunktodensity,
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1533,6 +1533,12 @@ class revlog(object):
     def issnapshot(self, rev):
         """tells whether rev is a snapshot
         """
+        if not self._generaldelta:
+            return self.deltaparent(rev) == nullrev
+        elif util.safehasattr(self.index, 'issnapshot'):
+            # directly assign the method to cache the testing and access
+            self.issnapshot = self.index.issnapshot
+            return self.issnapshot(rev)
         if rev == nullrev:
             return True
         entry = self.index[rev]


More information about the Mercurial-devel mailing list