Patchwork [4,of,8] perf: add functions to get vfs-like object for Mercurial earlier than 2.3

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Aug. 8, 2016, 9:59 a.m.
Message ID <df55e03628eb84cf0477.1470650383@juju>
Download mbox | patch
Permalink /patch/16192/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Katsunori FUJIWARA - Aug. 8, 2016, 9:59 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1470649697 -32400
#      Mon Aug 08 18:48:17 2016 +0900
# Node ID df55e03628eb84cf04770c964c90c4f401d30c4d
# Parent  246936fc48ebc95a6f820589cc8a0d765fcf1967
perf: add functions to get vfs-like object for Mercurial earlier than 2.3

Before this patch, using svfs prevents perf.py from measuring
performance of Mercurial earlier than 2.3 (or 7034365089bf), because
svfs isn't available in such Mercurial, even though there are some
code paths for Mercurial earlier than 2.3.

For example, setting "_prereadsize" attribute in perfindex() and
perfnodelookup() is effective only with hg earlier than 1.8 (or
61c9bc3da402).

To get appropriate vfs-like object to access files under .hg/store,
this patch adds getsvfs() (and also getvfs(), for future use).

To avoid examining existence of attribute at each repetition while
measuring performance, getsvfs() is invoked outside the function to be
called repeatedly.

This patch also adds check-perf-code.py an extra check entry to detect
direct usage of repo.(vfs|svfs|opener|sopener) in perf.py.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -232,6 +232,28 @@  def getbranchmapsubsettable():
     raise error.Abort(("perfbranchmap not available with this Mercurial"),
                       hint="use 2.5 or later")
 
+def getsvfs(repo):
+    """Return appropriate object to access files under .hg/store
+    """
+    # for "historical portability":
+    # repo.svfs has been available since 2.3 (or 7034365089bf)
+    svfs = getattr(repo, 'svfs', None)
+    if svfs:
+        return svfs
+    else:
+        return getattr(repo, 'sopener')
+
+def getvfs(repo):
+    """Return appropriate object to access files under .hg
+    """
+    # for "historical portability":
+    # repo.vfs has been available since 2.3 (or 7034365089bf)
+    vfs = getattr(repo, 'vfs', None)
+    if vfs:
+        return vfs
+    else:
+        return getattr(repo, 'opener')
+
 # perf commands
 
 @command('perfwalk', formatteropts)
@@ -302,9 +324,10 @@  def perftags(ui, repo, **opts):
     import mercurial.changelog
     import mercurial.manifest
     timer, fm = gettimer(ui, opts)
+    svfs = getsvfs(repo)
     def t():
-        repo.changelog = mercurial.changelog.changelog(repo.svfs)
-        repo.manifest = mercurial.manifest.manifest(repo.svfs)
+        repo.changelog = mercurial.changelog.changelog(svfs)
+        repo.manifest = mercurial.manifest.manifest(svfs)
         repo._tags = None
         return len(repo.tags())
     timer(t)
@@ -452,8 +475,9 @@  def perfindex(ui, repo, **opts):
     timer, fm = gettimer(ui, opts)
     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
     n = repo["tip"].node()
-    def d():
-        cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
+    svfs = getsvfs(repo)
+    def d():
+        cl = mercurial.revlog.revlog(svfs, "00changelog.i")
         cl.rev(n)
     timer(d)
     fm.end()
@@ -525,7 +549,7 @@  def perfnodelookup(ui, repo, rev, **opts
     import mercurial.revlog
     mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
     n = repo[rev].node()
-    cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i")
+    cl = mercurial.revlog.revlog(getsvfs(repo), "00changelog.i")
     def d():
         cl.rev(n)
         clearcaches(cl)
@@ -862,7 +886,8 @@  def perfloadmarkers(ui, repo):
 
     Result is the number of markers in the repo."""
     timer, fm = gettimer(ui)
-    timer(lambda: len(obsolete.obsstore(repo.svfs)))
+    svfs = getsvfs(repo)
+    timer(lambda: len(obsolete.obsstore(svfs)))
     fm.end()
 
 @command('perflrucachedict', formatteropts +
diff --git a/tests/check-perf-code.py b/tests/check-perf-code.py
--- a/tests/check-perf-code.py
+++ b/tests/check-perf-code.py
@@ -12,6 +12,8 @@  perfpypats = [
   [
     (r'(branchmap|repoview)\.subsettable',
      "use getbranchmapsubsettable() for early Mercurial"),
+    (r'\.(vfs|svfs|opener|sopener)',
+     "use getvfs()/getsvfs() for early Mercurial"),
   ],
   # warnings
   [