Mercurial > hg
view mercurial/unionrepo.py @ 43198:c16fe77e340a
pathcopies: give up any optimization based on `introrev`
Between 8a0136f69027 and d98fb3f42f33, we sped up the search for the
introduction revision during path copies. However, further checking show that
finding the introduction revision is still expensive and that we are better off
without it. So we simply drop it and only rely on the linkrev optimisation.
I ran `perfpathcopies` on 6989 pair of revision in the pypy
repository (`hg perfhelper-pathcopies`. The result is massively in favor of
dropping this condition. The result of the copy tracing are unchanged.
Attempt to use a smaller changes preserving linkrev usage were unsuccessful, it
can return wrong result. The following changesets broke test-mv-cp-st-diff.t
- if not f.isintroducedafter(limit):
+ if limit >= 0 and f.linkrev() < limit:
return None
Here are various numbers (before this changeset/after this changesets)
source destination before after saved-time ratio
worth cases e66f24650daf 695dfb0f493b 1.062843 1.246369 -0.183526 1.172675
c979853a3b6a 8d60fe293e79 1.036985 1.196414 -0.159429 1.153743
22349fa2fc33 fbb1c9fd86c0 0.879926 1.038682 -0.158756 1.180420
682b98f3e672 a4878080a536 0.909952 1.063801 -0.153849 1.169074
5adabc9b9848 920958a93997 0.993622 1.147452 -0.153830 1.154817
worse 1% dbfbfcf077e9 aea8f2fd3593 1.016595 1.082999 -0.066404 1.065320
worse 5% c95f1ced15f2 7d29d5e39734 0.453694 0.471156 -0.017462 1.038488
worse 10% 3e144ed1d5b7 2aef0e942480 0.035140 0.037535 -0.002395 1.068156
worse 25% 321fc60db035 801748ba582a 0.009267 0.009325 -0.000058 1.006259
median 2088ce763fc2 e6991321d78b 0.000665 0.000651 0.000014 0.978947
best 25% 915631a97de6 385b31354be6 0.040743 0.040363 0.000380 0.990673
best 10% ad495c36a765 19c10384d3e7 0.431658 0.411490 0.020168 0.953278
best 5% d13ae7d283ae 813c99f810ac 1.141404 1.075346 0.066058 0.942126
best 1% 81593cb4a496 99ae11866969 1.833297 0.063823 1.769474 0.034813
best cases c3b14617fbd7 743a0fcaa4eb 1101.811740 2.735970 1099.075770 0.002483
c3b14617fbd7 9ba6ab77fd29 1116.753953 2.800729 1113.953224 0.002508
058b99d6e81f 57e249b7a3ea 1246.128485 3.042762 1243.085723 0.002442
9a8c361aab49 0354a250d371 1253.111894 3.085796 1250.026098 0.002463
442dbbc53c68 3ec1002a818c 1261.786294 3.138607 1258.647687 0.002487
As one can see, the average case is not really impacted. However, the worth case
we get after this changeset are much better than the one we had before it. We
have 30 pairs where improvements are above 10 minutes.
This reflect in the combined time for all pairs
before: 26256s
after: 1300s (-95%)
If we remove these pathological 30 cases, we still see a significant improvements:
before: 1631s
after: 1245s (-24%)
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 10 Oct 2019 03:49:33 +0200 |
parents | c59eb1560c44 |
children | 642433629e20 |
line wrap: on
line source
# unionrepo.py - repository class for viewing union of repository changesets # # Derived from bundlerepo.py # Copyright 2006, 2007 Benoit Boissinot <bboissin@gmail.com> # Copyright 2013 Unity Technologies, Mads Kiilerich <madski@unity3d.com> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. """Repository class for "in-memory pull" of one local repository to another, allowing operations like diff and log with revsets. """ from __future__ import absolute_import from .i18n import _ from .pycompat import getattr from . import ( changelog, cmdutil, encoding, error, filelog, localrepo, manifest, mdiff, pathutil, revlog, util, vfs as vfsmod, ) class unionrevlog(revlog.revlog): def __init__(self, opener, indexfile, revlog2, linkmapper): # How it works: # To retrieve a revision, we just need to know the node id so we can # look it up in revlog2. # # To differentiate a rev in the second revlog from a rev in the revlog, # we check revision against repotiprev. opener = vfsmod.readonlyvfs(opener) revlog.revlog.__init__(self, opener, indexfile) self.revlog2 = revlog2 n = len(self) self.repotiprev = n - 1 self.bundlerevs = set() # used by 'bundle()' revset expression for rev2 in self.revlog2: rev = self.revlog2.index[rev2] # rev numbers - in revlog2, very different from self.rev _start, _csize, rsize, base, linkrev, p1rev, p2rev, node = rev flags = _start & 0xFFFF if linkmapper is None: # link is to same revlog assert linkrev == rev2 # we never link back link = n else: # rev must be mapped from repo2 cl to unified cl by linkmapper link = linkmapper(linkrev) if linkmapper is not None: # link is to same revlog base = linkmapper(base) if node in self.nodemap: # this happens for the common revlog revisions self.bundlerevs.add(self.nodemap[node]) continue p1node = self.revlog2.node(p1rev) p2node = self.revlog2.node(p2rev) # TODO: it's probably wrong to set compressed length to None, but # I have no idea if csize is valid in the base revlog context. e = ( flags, None, rsize, base, link, self.rev(p1node), self.rev(p2node), node, ) self.index.append(e) self.nodemap[node] = n self.bundlerevs.add(n) n += 1 def _chunk(self, rev): if rev <= self.repotiprev: return revlog.revlog._chunk(self, rev) return self.revlog2._chunk(self.node(rev)) def revdiff(self, rev1, rev2): """return or calculate a delta between two revisions""" if rev1 > self.repotiprev and rev2 > self.repotiprev: return self.revlog2.revdiff( self.revlog2.rev(self.node(rev1)), self.revlog2.rev(self.node(rev2)), ) elif rev1 <= self.repotiprev and rev2 <= self.repotiprev: return super(unionrevlog, self).revdiff(rev1, rev2) return mdiff.textdiff(self.rawdata(rev1), self.rawdata(rev2)) def _revisiondata(self, nodeorrev, _df=None, raw=False): if isinstance(nodeorrev, int): rev = nodeorrev node = self.node(rev) else: node = nodeorrev rev = self.rev(node) if rev > self.repotiprev: # work around manifestrevlog NOT being a revlog revlog2 = getattr(self.revlog2, '_revlog', self.revlog2) func = revlog2._revisiondata else: func = super(unionrevlog, self)._revisiondata return func(node, _df=_df, raw=raw) def addrevision(self, text, transaction, link, p1=None, p2=None, d=None): raise NotImplementedError def addgroup( self, deltas, linkmapper, transaction, addrevisioncb=None, maybemissingparents=False, ): raise NotImplementedError def strip(self, minlink, transaction): raise NotImplementedError def checksize(self): raise NotImplementedError class unionchangelog(unionrevlog, changelog.changelog): def __init__(self, opener, opener2): changelog.changelog.__init__(self, opener) linkmapper = None changelog2 = changelog.changelog(opener2) unionrevlog.__init__( self, opener, self.indexfile, changelog2, linkmapper ) class unionmanifest(unionrevlog, manifest.manifestrevlog): def __init__(self, opener, opener2, linkmapper): manifest.manifestrevlog.__init__(self, opener) manifest2 = manifest.manifestrevlog(opener2) unionrevlog.__init__( self, opener, self.indexfile, manifest2, linkmapper ) class unionfilelog(filelog.filelog): def __init__(self, opener, path, opener2, linkmapper, repo): filelog.filelog.__init__(self, opener, path) filelog2 = filelog.filelog(opener2, path) self._revlog = unionrevlog( opener, self.indexfile, filelog2._revlog, linkmapper ) self._repo = repo self.repotiprev = self._revlog.repotiprev self.revlog2 = self._revlog.revlog2 def iscensored(self, rev): """Check if a revision is censored.""" if rev <= self.repotiprev: return filelog.filelog.iscensored(self, rev) node = self.node(rev) return self.revlog2.iscensored(self.revlog2.rev(node)) class unionpeer(localrepo.localpeer): def canpush(self): return False class unionrepository(object): """Represents the union of data in 2 repositories. Instances are not usable if constructed directly. Use ``instance()`` or ``makeunionrepository()`` to create a usable instance. """ def __init__(self, repo2, url): self.repo2 = repo2 self._url = url self.ui.setconfig(b'phases', b'publish', False, b'unionrepo') @localrepo.unfilteredpropertycache def changelog(self): return unionchangelog(self.svfs, self.repo2.svfs) @localrepo.unfilteredpropertycache def manifestlog(self): rootstore = unionmanifest( self.svfs, self.repo2.svfs, self.unfiltered()._clrev ) return manifest.manifestlog( self.svfs, self, rootstore, self.narrowmatch() ) def _clrev(self, rev2): """map from repo2 changelog rev to temporary rev in self.changelog""" node = self.repo2.changelog.node(rev2) return self.changelog.rev(node) def url(self): return self._url def file(self, f): return unionfilelog( self.svfs, f, self.repo2.svfs, self.unfiltered()._clrev, self ) def close(self): self.repo2.close() def cancopy(self): return False def peer(self): return unionpeer(self) def getcwd(self): return encoding.getcwd() # always outside the repo def instance(ui, path, create, intents=None, createopts=None): if create: raise error.Abort(_(b'cannot create new union repository')) parentpath = ui.config(b"bundle", b"mainreporoot") if not parentpath: # try to find the correct path to the working directory repo parentpath = cmdutil.findrepo(encoding.getcwd()) if parentpath is None: parentpath = b'' if parentpath: # Try to make the full path relative so we get a nice, short URL. # In particular, we don't want temp dir names in test outputs. cwd = encoding.getcwd() if parentpath == cwd: parentpath = b'' else: cwd = pathutil.normasprefix(cwd) if parentpath.startswith(cwd): parentpath = parentpath[len(cwd) :] if path.startswith(b'union:'): s = path.split(b":", 1)[1].split(b"+", 1) if len(s) == 1: repopath, repopath2 = parentpath, s[0] else: repopath, repopath2 = s else: repopath, repopath2 = parentpath, path return makeunionrepository(ui, repopath, repopath2) def makeunionrepository(ui, repopath1, repopath2): """Make a union repository object from 2 local repo paths.""" repo1 = localrepo.instance(ui, repopath1, create=False) repo2 = localrepo.instance(ui, repopath2, create=False) url = b'union:%s+%s' % ( util.expandpath(repopath1), util.expandpath(repopath2), ) class derivedunionrepository(unionrepository, repo1.__class__): pass repo = repo1 repo.__class__ = derivedunionrepository unionrepository.__init__(repo1, repo2, url) return repo