[PATCH 2 of 5] revsetlang: build optimized tree by helper function

Jun Wu quark at fb.com
Thu Aug 31 21:15:12 EDT 2017


Excerpts from Augie Fackler's message of 2017-08-31 15:23:57 -0400:
> On Thu, Aug 31, 2017 at 11:42:11PM +0900, Yuya Nishihara wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya at tcha.org>
> > # Date 1455712705 -32400
> > #      Wed Feb 17 21:38:25 2016 +0900
> > # Node ID 937f5edf91058c63fafd981a59feaaaa98d21068
> > # Parent  1d58bfbb617075b997d4b0a41924fcaee648b32f
> > revsetlang: build optimized tree by helper function
> >
> > This should make optimize() more readable, but it doubles the parsing cost.
> >
> >   (original)
> >   $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
> >   'L.optimize(L.analyze(L.parse("::tip")))'
> >   10000 loops, best of 3: 18.1 usec per loop
> >
> >   (this patch)
> >   $ python -m timeit -n10000 -s 'from mercurial import revsetlang as L' \
> >   'L._treecache.clear(); L.optimize(L.analyze(L.parse("::tip")))'
> >   10000 loops, best of 3: 48.4 usec per loop
> >
> > 30usec isn't dominant compared to the revset evaluation, but that is a cost.
> > That's why a parsed tree is cached, which can benefit in hgweb or chg server.
> >
> > diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
> > --- a/mercurial/revsetlang.py
> > +++ b/mercurial/revsetlang.py
> > @@ -239,6 +239,25 @@ def getargsdict(x, funcname, keys):
> >      return parser.buildargsdict(getlist(x), funcname, parser.splitargspec(keys),
> >                                  keyvaluenode='keyvalue', keynode='symbol')
> >
> > +# cache of {spec: raw parsed tree} built internally
> > +_treecache = {}
> 
> Should this be an LRU cache that's very large, instead of an unbounded
> cache? Otherwise long-lived hgweb servers might end up using quite a
> bit of RAM?

Probably not. It's only used internally with static strings. User input
won't reach here.

> [...]


More information about the Mercurial-devel mailing list