[stringtemplate-interest] String template compiler
Sam Harwell
sharwell at pixelminegames.com
Thu Jun 18 11:14:30 PDT 2009
Hi Graham,
I've worked to some extent on dynamically compiling ST in the new C#
port. The code can be browsed at
http://fisheye2.atlassian.com/browse/antlrcs/ in the
Antlr3.StringTemplate subdirectory. Three alternatives are included in
the source.
1. Near direct translation of the Java code.
2. Composition of lambda methods during the ST parse stage.
3. Manual code generation through DynamicMethod.
The code for the compiled techniques is found in the following files:
* ActionEvaluator.g3 (and the generated ActionEvaluator.cs)
* ActionEvaluatorHelper.cs
* ASTExpr.cs
* ConditionalExpr.cs
Both of the compilation techniques produced good performance results.
Ported Java
Functors
DynamicMethod
Maintainability
Excellent
Good
Poor
Debugging
Excellent
Very good
Poor
Parse and compile time
Good
Excellent
Poor*
Memory usage
Moderate
Good**
Excellent
Execution time
Poor
Very good
Excellent***
The Grade
16
19
13
* This should be avoided by parsing once and GetInstanceOf for each
usage. It's so slow that it makes DynamicMethod the slowest overall
technique for minimal-reuse templates (1-10? usages maybe).
** I haven't evaluated how functor caching affects this.
*** This is an asymptotic characteristic for high-reuse templates.
Overall, the technique using lambda methods appears to be the superior
choice. The following combination of build macros and constants should
be a decent place to start testing:
1. Define the COMPILE_EXPRESSIONS build macro.
2. Optionally define the CACHE_FUNCTORS build macro. I believe it
would provide good results if you are caching your templates, but might
leak memory over time.
3. Set ASTExpr.EnableDynamicMethods = false. (This is the
default.)
4. Set ASTExpr.EnableFunctionalMethods = true. (This is the
default.)
There was long thread (subject "StringTemplate Compiler for .NET", Feb.
28 '09 through Apr. 1 '09) on this list talking about how to further
optimize ST, but I haven't implemented several of the items discussed.
I'm planning on traveling to USF in late July for a brainstorming
session on future ANTLR/ST optimization.
Sam
From: stringtemplate-interest-bounces at antlr.org
[mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Graham
Brooks
Sent: Thursday, June 18, 2009 9:48 AM
To: stringtemplate-interest at antlr.org
Subject: [stringtemplate-interest] String template compiler
All,
I am part of a team that is completing work on the first phase of a web
application using StringTemplate. As we have continued to tune the
performance of the application StringTemplate AST execution has emerged
as a hot spot. Application and template updates are part of application
deployment so we have already turned on template caching. One of the
options open to us is to write a compiler to improve template rendering
performance. I have exchanged a couple of email with Terence and he
suggested I reach out to this list for a few pointers.
Thanks in advance...
Graham
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090618/b8758480/attachment-0001.html
More information about the stringtemplate-interest
mailing list