Mercurial > public > mercurial-scm > hg
diff mercurial/commands.py @ 44865:233ee525dcef
grep: reduce the cost of pathauditor checks when grepping working copy
Running `time hg grep zxczxczxczxczxc -l` on mozilla-central:
before:
real 0m20,000s
user 0m15,796s
sys 0m4,189s
after:
real 0m10,903s
user 0m8,964s
sys 0m1,916s
if vfs didn't call pathauditor at all:
real 0m7,781s
user 0m5,968s
sys 0m1,790s
Differential Revision: https://phab.mercurial-scm.org/D8582
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 25 May 2020 17:39:23 -0400 |
parents | b7808443ed6a |
children | 61719b9658b1 |
line wrap: on
line diff
--- a/mercurial/commands.py Mon May 25 17:32:25 2020 -0400 +++ b/mercurial/commands.py Mon May 25 17:39:23 2020 -0400 @@ -3609,31 +3609,38 @@ parent = pctx.rev() matches.setdefault(parent, {}) files = revfiles.setdefault(rev, []) - for fn in fns: - # fn might not exist in the revision (could be a file removed by the - # revision). We could check `fn not in ctx` even when rev is None, - # but it's less racy to protect againt that in readfile. - if rev is not None and fn not in ctx: - continue - - copy = None - if follow: - copy = getrenamed(fn, rev) - if copy: - copies.setdefault(rev, {})[fn] = copy - if fn in skip: - skip.add(copy) - if fn in skip: - continue - files.append(fn) - - if fn not in matches[rev]: - grepbody(fn, rev, readfile(ctx, fn)) - - if diff: - pfn = copy or fn - if pfn not in matches[parent] and pfn in pctx: - grepbody(pfn, parent, readfile(pctx, pfn)) + if rev is None: + # in `hg grep pattern`, 2/3 of the time is spent is spent in + # pathauditor checks without this in mozilla-central + contextmanager = repo.wvfs.audit.cached + else: + contextmanager = util.nullcontextmanager + with contextmanager(): + for fn in fns: + # fn might not exist in the revision (could be a file removed by + # the revision). We could check `fn not in ctx` even when rev is + # None, but it's less racy to protect againt that in readfile. + if rev is not None and fn not in ctx: + continue + + copy = None + if follow: + copy = getrenamed(fn, rev) + if copy: + copies.setdefault(rev, {})[fn] = copy + if fn in skip: + skip.add(copy) + if fn in skip: + continue + files.append(fn) + + if fn not in matches[rev]: + grepbody(fn, rev, readfile(ctx, fn)) + + if diff: + pfn = copy or fn + if pfn not in matches[parent] and pfn in pctx: + grepbody(pfn, parent, readfile(pctx, pfn)) ui.pager(b'grep') fm = ui.formatter(b'grep', opts)