##// END OF EJS Templates
compression: introduce a `storage.revlog.zlib.level` configuration...
compression: introduce a `storage.revlog.zlib.level` configuration This option control the zlib compression level used when compression revlog chunk. This is also a good excuse to pave the way for a similar configuration option for the zstd compression engine. Having a dedicated option for each compression algorithm is useful because they don't support the same range of values. Using a higher zlib compression impact CPU consumption at compression time, but does not directly affected decompression time. However dealing with small compressed chunk can directly help decompression and indirectly help other revlog logic. I ran some basic test on repositories using different level. I am using the mercurial, pypy, netbeans and mozilla-central clone from our benchmark suite. All tested repository use sparse-revlog and got all their delta recomputed. The different compression level has a small effect on the repository size (about 10% variation in the total range). My quick analysis is that revlog mostly store small delta, that are not affected by the compression level much. So the variation probably mostly comes from better compression of the snapshots revisions, and snapshot revision only represent a small portion of the repository content. I also made some basic timings measurements. The "read" timings are gathered using simple run of `hg perfrevlogrevisions`, the "write" timings using `hg perfrevlogwrite` (restricted to the last 5000 revisions for netbeans and mozilla central). The timings are gathered on a generic machine, (not one of our performance locked machine), so small variation might not be meaningful. However large trend remains relevant. Keep in mind that these numbers are not pure compression/decompression time. They also involve the full revlog logic. In particular the difference in chunk size has an impact on the delta chain structure, affecting performance when writing or reading them. On read/write performance, the compression level has a bigger impact. Counter-intuitively, the higher compression levels improve "write" performance for the large repositories in our tested setting. Maybe because the last 5000 delta chain end up having a very different shape in this specific spot? Or maybe because of a more general trend of better delta chains thanks to the smaller chunk and snapshot. This series does not intend to change the default compression level. However, these result call for a deeper analysis of this performance difference in the future. Full data ========= repo level .hg/store size 00manifest.d read write ---------------------------------------------------------------- mercurial 1 49,402,813 5,963,475 0.170159 53.250304 mercurial 6 47,197,397 5,875,730 0.182820 56.264320 mercurial 9 47,121,596 5,849,781 0.189219 56.293612 pypy 1 370,830,572 28,462,425 2.679217 460.721984 pypy 6 340,112,317 27,648,747 2.768691 467.537158 pypy 9 338,360,736 27,639,003 2.763495 476.589918 netbeans 1 1,281,847,810 165,495,457 122.477027 520.560316 netbeans 6 1,205,284,353 159,161,207 139.876147 715.930400 netbeans 9 1,197,135,671 155,034,586 141.620281 678.297064 mozilla 1 2,775,497,186 298,527,987 147.867662 751.263721 mozilla 6 2,596,856,420 286,597,671 170.572118 987.056093 mozilla 9 2,587,542,494 287,018,264 163.622338 739.803002

File last commit:

r40873:901f6ef6 default
r42210:1fac9b93 default
Show More
commands.py
285 lines | 11.2 KiB | text/x-python | PythonLexer
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 # Copyright 2016-present Facebook. All Rights Reserved.
#
# commands: fastannotate commands
#
# 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 os
from mercurial.i18n import _
from mercurial import (
commands,
Matt Harbison
py3: rename pycompat.getcwd() to encoding.getcwd() (API)...
r39843 encoding,
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 error,
extensions,
patch,
pycompat,
registrar,
scmutil,
util,
)
from . import (
context as facontext,
error as faerror,
formatter as faformatter,
)
cmdtable = {}
command = registrar.command(cmdtable)
def _matchpaths(repo, rev, pats, opts, aopts=facontext.defaultopts):
"""generate paths matching given patterns"""
perfhack = repo.ui.configbool('fastannotate', 'perfhack')
# disable perfhack if:
# a) any walkopt is used
# b) if we treat pats as plain file names, some of them do not have
# corresponding linelog files
if perfhack:
# cwd related to reporoot
reporoot = os.path.dirname(repo.path)
Matt Harbison
py3: rename pycompat.getcwd() to encoding.getcwd() (API)...
r39843 reldir = os.path.relpath(encoding.getcwd(), reporoot)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 if reldir == '.':
reldir = ''
if any(opts.get(o[1]) for o in commands.walkopts): # a)
perfhack = False
else: # b)
relpats = [os.path.relpath(p, reporoot) if os.path.isabs(p) else p
for p in pats]
# disable perfhack on '..' since it allows escaping from the repo
if any(('..' in f or
not os.path.isfile(
facontext.pathhelper(repo, f, aopts).linelogpath))
for f in relpats):
perfhack = False
# perfhack: emit paths directory without checking with manifest
# this can be incorrect if the rev dos not have file.
if perfhack:
for p in relpats:
yield os.path.join(reldir, p)
else:
def bad(x, y):
raise error.Abort("%s: %s" % (x, y))
ctx = scmutil.revsingle(repo, rev)
m = scmutil.match(ctx, pats, opts, badfn=bad)
for p in ctx.walk(m):
yield p
fastannotatecommandargs = {
Pulkit Goyal
py3: add r'' prefix to prevent b'' being prepended...
r39443 r'options': [
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 ('r', 'rev', '.', _('annotate the specified revision'), _('REV')),
('u', 'user', None, _('list the author (long with -v)')),
('f', 'file', None, _('list the filename')),
('d', 'date', None, _('list the date (short with -q)')),
('n', 'number', None, _('list the revision number (default)')),
('c', 'changeset', None, _('list the changeset')),
('l', 'line-number', None, _('show line number at the first '
'appearance')),
('e', 'deleted', None, _('show deleted lines (slow) (EXPERIMENTAL)')),
('', 'no-content', None, _('do not show file content (EXPERIMENTAL)')),
('', 'no-follow', None, _("don't follow copies and renames")),
('', 'linear', None, _('enforce linear history, ignore second parent '
'of merges (EXPERIMENTAL)')),
('', 'long-hash', None, _('show long changeset hash (EXPERIMENTAL)')),
('', 'rebuild', None, _('rebuild cache even if it exists '
'(EXPERIMENTAL)')),
] + commands.diffwsopts + commands.walkopts + commands.formatteropts,
Pulkit Goyal
py3: add r'' prefix to prevent b'' being prepended...
r39443 r'synopsis': _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
r'inferrepo': True,
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 }
def fastannotate(ui, repo, *pats, **opts):
"""show changeset information by line for each file
List changes in files, showing the revision id responsible for each line.
This command is useful for discovering when a change was made and by whom.
By default this command prints revision numbers. If you include --file,
--user, or --date, the revision number is suppressed unless you also
include --number. The default format can also be customized by setting
fastannotate.defaultformat.
Returns 0 on success.
.. container:: verbose
This command uses an implementation different from the vanilla annotate
command, which may produce slightly different (while still reasonable)
outputs for some cases.
Unlike the vanilla anootate, fastannotate follows rename regardless of
the existence of --file.
For the best performance when running on a full repo, use -c, -l,
avoid -u, -d, -n. Use --linear and --no-content to make it even faster.
For the best performance when running on a shallow (remotefilelog)
repo, avoid --linear, --no-follow, or any diff options. As the server
won't be able to populate annotate cache when non-default options
affecting results are used.
"""
if not pats:
raise error.Abort(_('at least one filename or pattern is required'))
# performance hack: filtered repo can be slow. unfilter by default.
if ui.configbool('fastannotate', 'unfilteredrepo'):
repo = repo.unfiltered()
Pulkit Goyal
py3: fix kwargs handling in hgext/fastannotate.py...
r39702 opts = pycompat.byteskwargs(opts)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 rev = opts.get('rev', '.')
rebuild = opts.get('rebuild', False)
diffopts = patch.difffeatureopts(ui, opts, section='annotate',
whitespace=True)
aopts = facontext.annotateopts(
diffopts=diffopts,
followmerge=not opts.get('linear', False),
followrename=not opts.get('no_follow', False))
if not any(opts.get(s)
for s in ['user', 'date', 'file', 'number', 'changeset']):
# default 'number' for compatibility. but fastannotate is more
# efficient with "changeset", "line-number" and "no-content".
for name in ui.configlist('fastannotate', 'defaultformat', ['number']):
opts[name] = True
ui.pager('fastannotate')
template = opts.get('template')
if template == 'json':
formatter = faformatter.jsonformatter(ui, repo, opts)
else:
formatter = faformatter.defaultformatter(ui, repo, opts)
showdeleted = opts.get('deleted', False)
showlines = not bool(opts.get('no_content'))
showpath = opts.get('file', False)
# find the head of the main (master) branch
master = ui.config('fastannotate', 'mainbranch') or rev
# paths will be used for prefetching and the real annotating
paths = list(_matchpaths(repo, rev, pats, opts, aopts))
# for client, prefetch from the server
if util.safehasattr(repo, 'prefetchfastannotate'):
repo.prefetchfastannotate(paths)
for path in paths:
result = lines = existinglines = None
while True:
try:
with facontext.annotatecontext(repo, path, aopts, rebuild) as a:
result = a.annotate(rev, master=master, showpath=showpath,
showlines=(showlines and
not showdeleted))
if showdeleted:
existinglines = set((l[0], l[1]) for l in result)
result = a.annotatealllines(
rev, showpath=showpath, showlines=showlines)
break
except (faerror.CannotReuseError, faerror.CorruptedFileError):
# happens if master moves backwards, or the file was deleted
# and readded, or renamed to an existing name, or corrupted.
if rebuild: # give up since we have tried rebuild already
raise
else: # try a second time rebuilding the cache (slow)
rebuild = True
continue
if showlines:
result, lines = result
formatter.write(result, lines, existinglines=existinglines)
formatter.end()
_newopts = set([])
_knownopts = set([opt[1].replace('-', '_') for opt in
Pulkit Goyal
py3: add r'' prefix to prevent b'' being prepended...
r39443 (fastannotatecommandargs[r'options'] + commands.globalopts)])
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
def _annotatewrapper(orig, ui, repo, *pats, **opts):
"""used by wrapdefault"""
# we need this hack until the obsstore has 0.0 seconds perf impact
if ui.configbool('fastannotate', 'unfilteredrepo'):
repo = repo.unfiltered()
# treat the file as text (skip the isbinary check)
if ui.configbool('fastannotate', 'forcetext'):
Pulkit Goyal
py3: fix kwargs handling in hgext/fastannotate.py...
r39702 opts[r'text'] = True
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
# check if we need to do prefetch (client-side)
Pulkit Goyal
py3: fix kwargs handling in hgext/fastannotate.py...
r39702 rev = opts.get(r'rev')
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 if util.safehasattr(repo, 'prefetchfastannotate') and rev is not None:
Pulkit Goyal
py3: fix kwargs handling in hgext/fastannotate.py...
r39702 paths = list(_matchpaths(repo, rev, pats, pycompat.byteskwargs(opts)))
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 repo.prefetchfastannotate(paths)
return orig(ui, repo, *pats, **opts)
def registercommand():
"""register the fastannotate command"""
Rodrigo Damazio
help: adding a proper declaration for shortlist/basic commands (API)...
r40331 name = 'fastannotate|fastblame|fa'
command(name, helpbasic=True, **fastannotatecommandargs)(fastannotate)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243
def wrapdefault():
"""wrap the default annotate command, to be aware of the protocol"""
extensions.wrapcommand(commands.table, 'annotate', _annotatewrapper)
@command('debugbuildannotatecache',
[('r', 'rev', '', _('build up to the specific revision'), _('REV'))
] + commands.walkopts,
_('[-r REV] FILE...'))
def debugbuildannotatecache(ui, repo, *pats, **opts):
"""incrementally build fastannotate cache up to REV for specified files
If REV is not specified, use the config 'fastannotate.mainbranch'.
If fastannotate.client is True, download the annotate cache from the
server. Otherwise, build the annotate cache locally.
The annotate cache will be built using the default diff and follow
options and lives in '.hg/fastannotate/default'.
"""
Pulkit Goyal
py3: fix kwargs handling in hgext/fastannotate.py...
r39702 opts = pycompat.byteskwargs(opts)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 rev = opts.get('REV') or ui.config('fastannotate', 'mainbranch')
if not rev:
raise error.Abort(_('you need to provide a revision'),
hint=_('set fastannotate.mainbranch or use --rev'))
if ui.configbool('fastannotate', 'unfilteredrepo'):
repo = repo.unfiltered()
ctx = scmutil.revsingle(repo, rev)
m = scmutil.match(ctx, pats, opts)
paths = list(ctx.walk(m))
if util.safehasattr(repo, 'prefetchfastannotate'):
# client
if opts.get('REV'):
raise error.Abort(_('--rev cannot be used for client'))
repo.prefetchfastannotate(paths)
else:
# server, or full repo
Martin von Zweigbergk
debugbuildannotatecache: use progress helper...
r40873 progress = ui.makeprogress(_('building'), total=len(paths))
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 for i, path in enumerate(paths):
Martin von Zweigbergk
debugbuildannotatecache: use progress helper...
r40873 progress.update(i)
Augie Fackler
fastannotate: initial import from Facebook's hg-experimental...
r39243 with facontext.annotatecontext(repo, path) as actx:
try:
if actx.isuptodate(rev):
continue
actx.annotate(rev, rev)
except (faerror.CannotReuseError, faerror.CorruptedFileError):
# the cache is broken (could happen with renaming so the
# file history gets invalidated). rebuild and try again.
ui.debug('fastannotate: %s: rebuilding broken cache\n'
% path)
actx.rebuild()
try:
actx.annotate(rev, rev)
except Exception as ex:
# possibly a bug, but should not stop us from building
# cache for other files.
ui.warn(_('fastannotate: %s: failed to '
'build cache: %r\n') % (path, ex))
Martin von Zweigbergk
debugbuildannotatecache: use progress helper...
r40873 progress.complete()