[stringtemplate-interest] StringTemplate Compiler for .NET
Terence Parr
parrt at cs.usfca.edu
Fri Mar 20 11:48:07 PDT 2009
excellent information. I will take advantage of these optimizations
for the next version.
I never bothered to optimize anything in ST so I guess there will be
plenty of opportunities :)
Ter
On Mar 19, 2009, at 1:23 AM, Volkan Ceylan wrote:
>> So here we go/you’ve inspired me. :) For syntax highlighting, view
>> in HTML.
>
> Wouv i'm glad, thats great, ;)
>
> I still don't have access to repository and can't see actual code.
> Prof. Parr could you please set up a readonly account for me to access
> ST#3 code?
>
> Btw, it would be great if expressions are compiled during parsing. As
> i didn't want to modify ST code myself, i choosed another way. I'm
> creating a set of dynamic methods/CompiledTemplate objects given a set
> of StringTemplate/StringTemplateGroup objects. So when the template is
> going to be converted to string with a new set of attributes by means
> of compiledTemplate.GetInstanceOf().ToString(), there won't be any
> dynamic compilation at this stage, just calls to dynamic methods. You
> are not generating dynamic methods on evaluation stage each time a
> template instance is converted to string, do you? It would be very
> slow, because of the way ILGenerator works (probably you don't, i
> couldn't have enough time to review code yet).
>
> I would like to point in some performance bottlenecks that i
> discovered during my development. Might be helpful if you are planning
> to keep on doing compilations / optimizations.
>
> - Anonymous templates (and most named templates) usually only have one
> (or none) argument, "it" or a named variant of it e.g. "x". And there
> is also
> "i" and "i0" special variables. Even when a template access only these
> attributes, a dictionary lookup is still required. And dictionary
> lookup is slow (yes O(1) but still 10x slower than a direct variable
> lookup). They should be treated specially in special template
> variables. I did this for compiled templates and it helped a lot.
> Templates with a single argument can also be treated specially.
>
> - Options like separator, format, null, anchor etc. are all string
> templates, even when they just contains of a constant simple string
> (And most of the time like %99 they are constants). When they are
> constants, they should also be treated specially.
>
> - There is a list called EmbeddedInstances in each StringTemplate.
> This list is not used anywhere, grows each time a template is
> converted to a string and it prevents garbage collection of template
> instances. Don't know if your port has them, but if it does, should be
> removed.
>
> - ASTExpr.ApplyListOfAlternatingTemplates is called even when there is
> only one template and it has array lookup/modulus overheads. Also it
> creates an array of templates for each element and returns that array
> as results may be applied to another template, but most of the time
> they don't. May be optimized by looking ahead in the expression tree
> to see if there is an upcoming template application.
>
> Volkan Ceylan
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list