Re: [PATCH 1 of 2] templatekw: add utility function numrevs
On Thu, 2018-01-18 at 21:03 +0900, Yuya Nishihara wrote: > On Wed, 17 Jan 2018 22:14:29 -0500, Jordi Gutiérrez Hermoso wrote: > > # HG changeset patch > > # User Jordi Gutiérrez Hermoso> > # Date 1516242948 18000 > > # Wed Jan 17 21:35:48 2018 -0500 > > # Node ID 701f8a9defdc09bb63f2596e2fc426f2e78da313 > > # Parent 0e369eca888fc80ee980fe8200c59dc7b0024dae > > templatekw: add utility function numrevs > > > > len(repo) calls incur noticeable overhead if called for each > > revision > > a template keyword is evaluated. > > Do you have some number? It's just a proxy to revlog.__len__(), so I > think it > is super fast. The Python function calls leading up to it are not that fast. Without this caching, it takes 7.2 seconds on average on my machine to to do `hg log -T '{negrev}\n' > /dev/null`. With the caching, it takes 6.4 seconds on average. Not a huge difference, but a difference. I wanted to match the speed of `hg log -T '{rev}\n' > /dev/null`, and this caching helped me match it. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Re: [PATCH 1 of 2] templatekw: add utility function numrevs
On Wed, 17 Jan 2018 22:14:29 -0500, Jordi Gutiérrez Hermoso wrote: > # HG changeset patch > # User Jordi Gutiérrez Hermoso> # Date 1516242948 18000 > # Wed Jan 17 21:35:48 2018 -0500 > # Node ID 701f8a9defdc09bb63f2596e2fc426f2e78da313 > # Parent 0e369eca888fc80ee980fe8200c59dc7b0024dae > templatekw: add utility function numrevs > > len(repo) calls incur noticeable overhead if called for each revision > a template keyword is evaluated. Do you have some number? It's just a proxy to revlog.__len__(), so I think it is super fast. > --- a/mercurial/templatekw.py > +++ b/mercurial/templatekw.py > @@ -852,6 +852,10 @@ def showrev(repo, ctx, templ, **args): > """Integer. The repository-local changeset revision number.""" > return scmutil.intrev(ctx) > > +@util.cachefunc > +def numrevs(repo): > +return len(repo) It leaks repo forever as the cache is keyed by arguments. args['cache'] can be used instead. ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
[PATCH 1 of 2] templatekw: add utility function numrevs
# HG changeset patch # User Jordi Gutiérrez Hermoso# Date 1516242948 18000 # Wed Jan 17 21:35:48 2018 -0500 # Node ID 701f8a9defdc09bb63f2596e2fc426f2e78da313 # Parent 0e369eca888fc80ee980fe8200c59dc7b0024dae templatekw: add utility function numrevs len(repo) calls incur noticeable overhead if called for each revision a template keyword is evaluated. We obviously can't cache __len__ functions in general because many commands modify the repo size. For template keywords, however, the repo is read-only so we can benefit from a cache. diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -852,6 +852,10 @@ def showrev(repo, ctx, templ, **args): """Integer. The repository-local changeset revision number.""" return scmutil.intrev(ctx) +@util.cachefunc +def numrevs(repo): +return len(repo) + def showrevslist(name, revs, **args): """helper to generate a list of revisions in which a mapped template will be evaluated""" ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel