[PATCH STABLE] hgweb: cache fctx.parents() in annotate command (issue5414)
Yuya Nishihara
yuya at tcha.org
Sat Nov 5 09:27:25 UTC 2016
On Fri, 04 Nov 2016 23:07:21 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1478325927 25200
> # Fri Nov 04 23:05:27 2016 -0700
> # Branch stable
> # Node ID b0dc7dd87fc8b5efee6e6d8c0bcc6ddfa52d6df3
> # Parent e5cc44ea12de681d971fcbebb65a7fb71fd1c3c7
> hgweb: cache fctx.parents() in annotate command (issue5414)
Looks good, but one nit.
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -861,12 +861,25 @@ def annotate(web, req, tmpl):
> f = fctx.path()
> parity = paritygen(web.stripecount)
>
> + # parents() is called once per line and several lines likely belong to
> + # same revision. So it is worth caching.
> + # TODO there are still redundant operations within basefilectx.parents()
> + # that could also be cached.
> + parentscache = {}
> def parents(f):
> - for p in f.parents():
> - yield {
> - "node": p.hex(),
> - "rev": p.rev(),
> - }
> + rev = f.rev()
> + if rev in parentscache:
> + for entry in parentscache[rev]:
> + yield entry
> + else:
> + parentscache[rev] = []
> + for p in f.parents():
> + entry = {
> + 'node': p.hex(),
> + 'rev': p.rev(),
> + }
> + parentscache[rev].append(entry)
> + yield entry
If the generator is stopped at the first yield, parentscache would be
incomplete.
More information about the Mercurial-devel
mailing list