[Request] [+- ] D8586: files: speed up `hg files` when no flags change display
valentin.gatienbaron (Valentin Gatien-Baron)
phabricator at mercurial-scm.org
Tue May 26 12:37:54 UTC 2020
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.
REVISION SUMMARY
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.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D8586
AFFECTED FILES
mercurial/cmdutil.py
CHANGE DETAILS
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2752,15 +2752,28 @@
ret = 1
needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint()
- for f in ctx.matches(m):
- fm.startitem()
- fm.context(ctx=ctx)
- if needsfctx:
- fc = ctx[f]
- fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags())
- fm.data(path=f)
- fm.plain(fmt % uipathfn(f))
- ret = 0
+ if fm.isplain() and not needsfctx:
+ # Fast path. The speed-up comes from skipping the formatter, and batching
+ # calls to ui.write.
+ buf = b''
+ for f in ctx.matches(m):
+ buf += fmt % uipathfn(f)
+ if len(buf) > 5000:
+ ui.write(buf)
+ buf = b''
+ ret = 0
+ if buf:
+ ui.write(buf)
+ else:
+ for f in ctx.matches(m):
+ fm.startitem()
+ fm.context(ctx=ctx)
+ if needsfctx:
+ fc = ctx[f]
+ fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags())
+ fm.data(path=f)
+ fm.plain(fmt % uipathfn(f))
+ ret = 0
for subpath in sorted(ctx.substate):
submatch = matchmod.subdirmatcher(subpath, m)
To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20200526/18867fbc/attachment-0001.html>
More information about the Mercurial-patches
mailing list