Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 44861:065421e12248
files: speed up `hg files` when no flags change display
It's not the first time I see slowness from this command slow down
tools built on top of hg.
The majority of the time is spent merely printing the result before
this change, which is clearly not how it should be (especially since
the computation of the result also looks slow).
Running `hg files` in mozilla-central:
parent revision: 1,260s
this commit: 0,683s
this commit without batching ui.write: 0,931s
this commit replacing the body of the loop with `pass`: 0,566s
This looks like a prime candidate for a rust fast path, but until
then, it seems reasonable to optimize the python.
Differential Revision: https://phab.mercurial-scm.org/D8586
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Tue, 26 May 2020 08:15:09 -0400 |
parents | b7808443ed6a |
children | c05ac059749f |
comparison
equal
deleted
inserted
replaced
44860:5d77f571a563 | 44861:065421e12248 |
---|---|
2750 | 2750 |
2751 def files(ui, ctx, m, uipathfn, fm, fmt, subrepos): | 2751 def files(ui, ctx, m, uipathfn, fm, fmt, subrepos): |
2752 ret = 1 | 2752 ret = 1 |
2753 | 2753 |
2754 needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint() | 2754 needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint() |
2755 for f in ctx.matches(m): | 2755 if fm.isplain() and not needsfctx: |
2756 fm.startitem() | 2756 # Fast path. The speed-up comes from skipping the formatter, and batching |
2757 fm.context(ctx=ctx) | 2757 # calls to ui.write. |
2758 if needsfctx: | 2758 buf = [] |
2759 fc = ctx[f] | 2759 for f in ctx.matches(m): |
2760 fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags()) | 2760 buf.append(fmt % uipathfn(f)) |
2761 fm.data(path=f) | 2761 if len(buf) > 100: |
2762 fm.plain(fmt % uipathfn(f)) | 2762 ui.write(b''.join(buf)) |
2763 ret = 0 | 2763 del buf[:] |
2764 ret = 0 | |
2765 if buf: | |
2766 ui.write(b''.join(buf)) | |
2767 else: | |
2768 for f in ctx.matches(m): | |
2769 fm.startitem() | |
2770 fm.context(ctx=ctx) | |
2771 if needsfctx: | |
2772 fc = ctx[f] | |
2773 fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags()) | |
2774 fm.data(path=f) | |
2775 fm.plain(fmt % uipathfn(f)) | |
2776 ret = 0 | |
2764 | 2777 |
2765 for subpath in sorted(ctx.substate): | 2778 for subpath in sorted(ctx.substate): |
2766 submatch = matchmod.subdirmatcher(subpath, m) | 2779 submatch = matchmod.subdirmatcher(subpath, m) |
2767 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) | 2780 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
2768 if subrepos or m.exact(subpath) or any(submatch.files()): | 2781 if subrepos or m.exact(subpath) or any(submatch.files()): |