[PATCH 1 of 6 RFC] localrepo: establish a base class for an immutable local repository

Gregory Szorc gregory.szorc at gmail.com
Fri Jun 9 06:36:05 UTC 2017


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1496977416 25200
#      Thu Jun 08 20:03:36 2017 -0700
# Node ID dfe0db942bbf860968b19fd8579865790d78d5e8
# Parent  e583b786ffba99cb775cf9d3a126cf50db74f85a
localrepo: establish a base class for an immutable local repository

Currently, localrepository has a number of properties that are cached
based on things changing. For attributes behind @repofilecache or
@storecache, we perform a stat() on every attribute access. If done
inside a tight loop, you have a perf killer. In the case of "changelog,"
the repoview layer maintains its own cache of which changesets are
visible. And this has to be consulted on every attribute lookup,
which can lead to performance loss, even if it is relatively fast.

Currently, localrepository model is "open the repo and constantly check
if things have changed." I strongly disagree with this model. I believe
an opened repository "handle" should either be an immutable and
globally consistent view of the repo at the time it was opened *or* be
mutable and represent evolving state changed by that process. The
current model of constantly checking if things changed leads to poor
performance by both introducing overhead and preventing aggressive
caching (if something is immutable, caching is easy). It also leads
to complicated and hard-to-reason-about APIs and caching.

This commit starts the process of breaking the localrepository class
into immutable and mutable classes. The end goal is for an
immutable repository instance to be obtained by default and for all
mutation operations to be performed on a mutable repo type. This
will naturally lead to optimization of read-only operations and
commands by removing cache checking.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -248,7 +248,10 @@ class locallegacypeer(localpeer):
 # clients.
 REVLOGV2_REQUIREMENT = 'exp-revlogv2.0'
 
-class localrepository(object):
+class immutablelocalrepository(object):
+    """An immutable repository on local disk."""
+
+class localrepository(immutablelocalrepository):
 
     supportedformats = {
         'revlogv1',


More information about the Mercurial-devel mailing list