Patchwork [2,of,7,V4] clfilter: add a cache on repo for set of revision to filter for a given set

login
register
mail settings
Submitter Pierre-Yves David
Date Dec. 20, 2012, 4:23 p.m.
Message ID <54f51cc8f3a34dac9617.1356020621@crater2.logilab.fr>
Download mbox | patch
Permalink /patch/218/
State Accepted
Headers show

Comments

Pierre-Yves David - Dec. 20, 2012, 4:23 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1356020047 -3600
# Node ID 54f51cc8f3a34dac96178a873e7aad5ad4fe207a
# Parent  11467c762b77075ad012f420ee993f21218324ec
clfilter: add a cache on repo for set of revision to filter for a given set.

Recomputing the filtered revisions at every access to changelog is far too
expensive. This changeset introduce a cache for this information. This cache is
hold by the repository (unfiltered repository) and invalidated when necessary.
This cache is not a protected attribute (leading _) because some logic that
invalidate it is not held by the local repo itself.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -237,10 +237,19 @@  class localrepository(object):
         # (used by the filecache decorator)
         #
         # Maps a property name to its util.filecacheentry
         self._filecache = {}
 
+        # hold sets of revision to be filtered
+        # should be cleared when something might have changed the filter value:
+        # - new changesets,
+        # - phase change,
+        # - new obsolescence marker,
+        # - working directory parent change,
+        # - bookmark changes
+        self.filteredrevcache = {}
+
     def close(self):
         pass
 
     def _restrictcapabilities(self, caps):
         return caps
@@ -1091,10 +1100,11 @@  class localrepository(object):
             del self.__dict__['_tagscache']
 
         self.unfiltered()._branchcache = None # in UTF-8
         self.unfiltered()._branchcachetip = None
         obsolete.clearobscaches(self)
+        self.filteredrevcache.clear()
 
     def invalidatedirstate(self):
         '''Invalidates the dirstate, causing the next call to dirstate
         to check if it was modified since the last time it was read,
         rereading it if it has.
@@ -1856,10 +1866,11 @@  class localrepository(object):
                         tr = self.transaction(trname)
                     for key in sorted(remoteobs, reverse=True):
                         if key.startswith('dump'):
                             data = base85.b85decode(remoteobs[key])
                             self.obsstore.mergemarkers(tr, data)
+                    self.filteredrevcache.clear()
             if tr is not None:
                 tr.close()
         finally:
             if tr is not None:
                 tr.release()
@@ -2468,10 +2479,11 @@  class localrepository(object):
 
             self.ui.status(_("added %d changesets"
                              " with %d changes to %d files%s\n")
                              % (changesets, revisions, files, htext))
             obsolete.clearobscaches(self)
+            self.filteredrevcache.clear()
 
             if changesets > 0:
                 p = lambda: cl.writepending() and self.root or ""
                 self.hook('pretxnchangegroup', throw=True,
                           node=hex(cl.node(clstart)), source=srctype,
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -736,8 +736,9 @@  def createmarkers(repo, relations, flag=
             nprec = prec.node()
             nsucs = tuple(s.node() for s in sucs)
             if nprec in nsucs:
                 raise util.Abort("changeset %s cannot obsolete itself" % prec)
             repo.obsstore.create(tr, nprec, nsucs, flag, metadata)
+            repo.filteredrevcache.clear()
         tr.close()
     finally:
         tr.release()
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -247,10 +247,11 @@  class phasecache(object):
                 delroots.extend(olds - roots)
             # declare deleted root in the target phase
             if targetphase != 0:
                 self.retractboundary(repo, targetphase, delroots)
         obsolete.clearobscaches(repo)
+        repo.filteredrevcache.clear()
 
     def retractboundary(self, repo, targetphase, nodes):
         # Be careful to preserve shallow-copied values: do not update
         # phaseroots values, replace them.
 
@@ -265,10 +266,11 @@  class phasecache(object):
             currentroots.update(newroots)
             ctxs = repo.set('roots(%ln::)', currentroots)
             currentroots.intersection_update(ctx.node() for ctx in ctxs)
             self._updateroots(targetphase, currentroots)
         obsolete.clearobscaches(repo)
+        repo.filteredrevcache.clear()
 
 def advanceboundary(repo, targetphase, nodes):
     """Add nodes to a phase changing other nodes phases if necessary.
 
     This function move boundary *forward* this means that all nodes
diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -11,11 +11,14 @@  import copy
 # function to compute filtered set
 filtertable = {}
 
 def filteredrevs(repo, filtername):
     """returns set of filtered revision for this filter name"""
-    return filtertable[filtername](repo.unfiltered())
+    if filtername not in repo.filteredrevcache:
+        func = filtertable[filtername]
+        repo.filteredrevcache[filtername] = func(repo.unfiltered())
+    return repo.filteredrevcache[filtername]
 
 class repoview(object):
     """Provide a read/write view of a repo through a filtered changelog
 
     This object is used to access a filtered version of a repository without