Mercurial > hg
view mercurial/repoview.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 | 1f339b503a40 |
children | 4353942be294 |
line wrap: on
line source
# repoview.py - Filtered view of a localrepo object # # Copyright 2012 Pierre-Yves David <pierre-yves.david@ens-lyon.org> # Logilab SA <contact@logilab.fr> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import import copy import weakref from .node import nullrev from .pycompat import ( delattr, getattr, setattr, ) from . import ( obsolete, phases, pycompat, tags as tagsmod, util, ) from .utils import repoviewutil def hideablerevs(repo): """Revision candidates to be hidden This is a standalone function to allow extensions to wrap it. Because we use the set of immutable changesets as a fallback subset in branchmap (see mercurial.utils.repoviewutils.subsettable), you cannot set "public" changesets as "hideable". Doing so would break multiple code assertions and lead to crashes.""" obsoletes = obsolete.getrevs(repo, b'obsolete') internals = repo._phasecache.getrevset(repo, phases.localhiddenphases) internals = frozenset(internals) return obsoletes | internals def pinnedrevs(repo): """revisions blocking hidden changesets from being filtered """ cl = repo.changelog pinned = set() pinned.update([par.rev() for par in repo[None].parents()]) pinned.update([cl.rev(bm) for bm in repo._bookmarks.values()]) tags = {} tagsmod.readlocaltags(repo.ui, repo, tags, {}) if tags: rev, nodemap = cl.rev, cl.nodemap pinned.update(rev(t[0]) for t in tags.values() if t[0] in nodemap) return pinned def _revealancestors(pfunc, hidden, revs): """reveals contiguous chains of hidden ancestors of 'revs' by removing them from 'hidden' - pfunc(r): a funtion returning parent of 'r', - hidden: the (preliminary) hidden revisions, to be updated - revs: iterable of revnum, (Ancestors are revealed exclusively, i.e. the elements in 'revs' are *not* revealed) """ stack = list(revs) while stack: for p in pfunc(stack.pop()): if p != nullrev and p in hidden: hidden.remove(p) stack.append(p) def computehidden(repo, visibilityexceptions=None): """compute the set of hidden revision to filter During most operation hidden should be filtered.""" assert not repo.changelog.filteredrevs hidden = hideablerevs(repo) if hidden: hidden = set(hidden - pinnedrevs(repo)) if visibilityexceptions: hidden -= visibilityexceptions pfunc = repo.changelog.parentrevs mutable = repo._phasecache.getrevset(repo, phases.mutablephases) visible = mutable - hidden _revealancestors(pfunc, hidden, visible) return frozenset(hidden) def computesecret(repo, visibilityexceptions=None): """compute the set of revision that can never be exposed through hgweb Changeset in the secret phase (or above) should stay unaccessible.""" assert not repo.changelog.filteredrevs secrets = repo._phasecache.getrevset(repo, phases.remotehiddenphases) return frozenset(secrets) def computeunserved(repo, visibilityexceptions=None): """compute the set of revision that should be filtered when used a server Secret and hidden changeset should not pretend to be here.""" assert not repo.changelog.filteredrevs # fast path in simple case to avoid impact of non optimised code hiddens = filterrevs(repo, b'visible') secrets = filterrevs(repo, b'served.hidden') if secrets: return frozenset(hiddens | secrets) else: return hiddens def computemutable(repo, visibilityexceptions=None): assert not repo.changelog.filteredrevs # fast check to avoid revset call on huge repo if any(repo._phasecache.phaseroots[1:]): getphase = repo._phasecache.phase maymutable = filterrevs(repo, b'base') return frozenset(r for r in maymutable if getphase(repo, r)) return frozenset() def computeimpactable(repo, visibilityexceptions=None): """Everything impactable by mutable revision The immutable filter still have some chance to get invalidated. This will happen when: - you garbage collect hidden changeset, - public phase is moved backward, - something is changed in the filtering (this could be fixed) This filter out any mutable changeset and any public changeset that may be impacted by something happening to a mutable revision. This is achieved by filtered everything with a revision number egal or higher than the first mutable changeset is filtered.""" assert not repo.changelog.filteredrevs cl = repo.changelog firstmutable = len(cl) for roots in repo._phasecache.phaseroots[1:]: if roots: firstmutable = min(firstmutable, min(cl.rev(r) for r in roots)) # protect from nullrev root firstmutable = max(0, firstmutable) return frozenset(pycompat.xrange(firstmutable, len(cl))) # function to compute filtered set # # When adding a new filter you MUST update the table at: # mercurial.utils.repoviewutil.subsettable # Otherwise your filter will have to recompute all its branches cache # from scratch (very slow). filtertable = { b'visible': computehidden, b'visible-hidden': computehidden, b'served.hidden': computesecret, b'served': computeunserved, b'immutable': computemutable, b'base': computeimpactable, } _basefiltername = list(filtertable) def extrafilter(ui): """initialize extra filter and return its id If extra filtering is configured, we make sure the associated filtered view are declared and return the associated id. """ frevs = ui.config(b'experimental', b'extra-filter-revs') if frevs is None: return None fid = pycompat.sysbytes(util.DIGESTS[b'sha1'](frevs).hexdigest())[:12] combine = lambda fname: fname + b'%' + fid subsettable = repoviewutil.subsettable if combine(b'base') not in filtertable: for name in _basefiltername: def extrafilteredrevs(repo, *args, **kwargs): baserevs = filtertable[name](repo, *args, **kwargs) extrarevs = frozenset(repo.revs(frevs)) return baserevs | extrarevs filtertable[combine(name)] = extrafilteredrevs if name in subsettable: subsettable[combine(name)] = combine(subsettable[name]) return fid def filterrevs(repo, filtername, visibilityexceptions=None): """returns set of filtered revision for this filter name visibilityexceptions is a set of revs which must are exceptions for hidden-state and must be visible. They are dynamic and hence we should not cache it's result""" if filtername not in repo.filteredrevcache: func = filtertable[filtername] if visibilityexceptions: return func(repo.unfiltered, visibilityexceptions) 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 altering the original repository object itself. We can not alter the original object for two main reasons: - It prevents the use of a repo with multiple filters at the same time. In particular when multiple threads are involved. - It makes scope of the filtering harder to control. This object behaves very closely to the original repository. All attribute operations are done on the original repository: - An access to `repoview.someattr` actually returns `repo.someattr`, - A write to `repoview.someattr` actually sets value of `repo.someattr`, - A deletion of `repoview.someattr` actually drops `someattr` from `repo.__dict__`. The only exception is the `changelog` property. It is overridden to return a (surface) copy of `repo.changelog` with some revisions filtered. The `filtername` attribute of the view control the revisions that need to be filtered. (the fact the changelog is copied is an implementation detail). Unlike attributes, this object intercepts all method calls. This means that all methods are run on the `repoview` object with the filtered `changelog` property. For this purpose the simple `repoview` class must be mixed with the actual class of the repository. This ensures that the resulting `repoview` object have the very same methods than the repo object. This leads to the property below. repoview.method() --> repo.__class__.method(repoview) The inheritance has to be done dynamically because `repo` can be of any subclasses of `localrepo`. Eg: `bundlerepo` or `statichttprepo`. """ def __init__(self, repo, filtername, visibilityexceptions=None): object.__setattr__(self, r'_unfilteredrepo', repo) object.__setattr__(self, r'filtername', filtername) object.__setattr__(self, r'_clcachekey', None) object.__setattr__(self, r'_clcache', None) # revs which are exceptions and must not be hidden object.__setattr__(self, r'_visibilityexceptions', visibilityexceptions) # not a propertycache on purpose we shall implement a proper cache later @property def changelog(self): """return a filtered version of the changeset this changelog must not be used for writing""" # some cache may be implemented later unfi = self._unfilteredrepo unfichangelog = unfi.changelog # bypass call to changelog.method unfiindex = unfichangelog.index unfilen = len(unfiindex) unfinode = unfiindex[unfilen - 1][7] revs = filterrevs(unfi, self.filtername, self._visibilityexceptions) cl = self._clcache newkey = (unfilen, unfinode, hash(revs), unfichangelog._delayed) # if cl.index is not unfiindex, unfi.changelog would be # recreated, and our clcache refers to garbage object if cl is not None and ( cl.index is not unfiindex or newkey != self._clcachekey ): cl = None # could have been made None by the previous if if cl is None: cl = copy.copy(unfichangelog) cl.filteredrevs = revs object.__setattr__(self, r'_clcache', cl) object.__setattr__(self, r'_clcachekey', newkey) return cl def unfiltered(self): """Return an unfiltered version of a repo""" return self._unfilteredrepo def filtered(self, name, visibilityexceptions=None): """Return a filtered version of a repository""" if name == self.filtername and not visibilityexceptions: return self return self.unfiltered().filtered(name, visibilityexceptions) def __repr__(self): return r'<%s:%s %r>' % ( self.__class__.__name__, pycompat.sysstr(self.filtername), self.unfiltered(), ) # everything access are forwarded to the proxied repo def __getattr__(self, attr): return getattr(self._unfilteredrepo, attr) def __setattr__(self, attr, value): return setattr(self._unfilteredrepo, attr, value) def __delattr__(self, attr): return delattr(self._unfilteredrepo, attr) # Python <3.4 easily leaks types via __mro__. See # https://bugs.python.org/issue17950. We cache dynamically created types # so they won't be leaked on every invocation of repo.filtered(). _filteredrepotypes = weakref.WeakKeyDictionary() def newtype(base): """Create a new type with the repoview mixin and the given base class""" if base not in _filteredrepotypes: class filteredrepo(repoview, base): pass _filteredrepotypes[base] = filteredrepo return _filteredrepotypes[base]