diff --git a/hgext3rd/perftweaks.py b/hgext3rd/perftweaks.py --- a/hgext3rd/perftweaks.py +++ b/hgext3rd/perftweaks.py @@ -12,6 +12,9 @@ # Whether to use faster hidden cache. It has faster cache hash calculation # which only check stat of a few files inside store/ directory. fasthiddencache = False + + # Reorder namespaces so "branches" and "tags" are at the last. + reordernamespaces = True """ from mercurial import ( @@ -19,6 +22,7 @@ dispatch, extensions, merge, + namespaces, phases, revlog, scmutil, @@ -65,10 +69,26 @@ except KeyError: pass + wrapfunction(namespaces.namespaces, 'singlenode', _singlenode) + def reposetup(ui, repo): if repo.local() is not None: _preloadrevs(repo) +def _singlenode(orig, self, repo, name): + """Skips reading tags or namespaces if unnecessary""" + names = self._names + namesbak = names.copy() + # branches only makes sense if name == 'default'. + # Loading 'branches' requires O(len(changelog)) time complexity because + # it calls headrevs() which scans the entire changelog. + if name != 'default' and 'branches' in names: + del names['branches'] + try: + return orig(self, repo, name) + finally: + self.names = namesbak + def _readtagcache(orig, ui, repo): """Disables reading tags if the repo is known to not contain any.""" if ui.configbool('perftweaks', 'disabletags'): @@ -201,6 +221,16 @@ def _cachefilename(name): return 'noderevs/%s' % name +def _namesiteritems(orig): + buffered = [] + for k, v in orig(): + if k in ('tags', 'branches'): + buffered.append((k, v)) + else: + yield k, v + for k, v in buffered: + yield k, v + def _preloadrevs(repo): # Preloading the node-rev map for likely to be used revs saves 100ms on # every command. This is because normally to look up a node, hg has to scan