[prev in list] [next in list] [prev in thread] [next in thread] 

List:       stringtemplate-interest
Subject:    Re: [stringtemplate-interest] String template compiler
From:       "Sam Harwell" <sharwell () pixelminegames ! com>
Date:       2009-06-18 18:14:30
Message-ID: 86403CA0939415448BCCB83855EFE09AA682D4 () Bloodymary ! ironwillgames ! com
[Download RAW message or body]

--===============3794425422983411538==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C9F040.9BD0A4AE"

This is a multi-part message in MIME format.


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@antlr.org
[mailto:stringtemplate-interest-bounces@antlr.org] On Behalf Of Graham
Brooks
Sent: Thursday, June 18, 2009 9:48 AM
To: stringtemplate-interest@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

 


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
	{font-family:"Brush Script MT";
	panose-1:3 6 8 2 4 4 6 7 3 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{mso-style-priority:34;
	margin-top:0in;
	margin-right:0in;
	margin-bottom:0in;
	margin-left:.5in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
span.apple-style-span
	{mso-style-name:apple-style-span;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:743631;
	mso-list-type:hybrid;
	mso-list-template-ids:-1499170684 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l0:level1
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l1
	{mso-list-id:521016341;
	mso-list-type:hybrid;
	mso-list-template-ids:825102900 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l1:level1
	{mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l2
	{mso-list-id:1759398253;
	mso-list-type:hybrid;
	mso-list-template-ids:-1217880224 322575020 67698691 67698693 67698689 67698691 \
67698693 67698689 67698691 67698693;} @list l2:level1
	{mso-level-number-format:bullet;
	mso-level-text:\F0B7;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-.25in;
	font-family:Symbol;
	mso-fareast-font-family:Calibri;
	mso-bidi-font-family:"Times New Roman";}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;
-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hi Graham,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I&#8217;ve worked to some extent on dynamically compiling ST in
the new C# port. The code can be browsed at <a
href="http://fisheye2.atlassian.com/browse/antlrcs/">http://fisheye2.atlassian.com/browse/antlrcs/</a>
 in the Antlr3.StringTemplate subdirectory. Three alternatives are included in
the source.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Near \
direct translation of the Java code.<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; \
color:#1F497D'>Composition of lambda methods during the ST parse \
stage.<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Manual \
code generation through </span><span style='font-size: \
8.0pt;font-family:Consolas'>DynamicMethod</span><span style='font-size:11.0pt; \
font-family:"Calibri","sans-serif";color:#1F497D'>.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>The code for the compiled techniques is found in the following
files:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l2 level1 lfo3'><![if \
!supportLists]><span style='font-size:11.0pt;font-family:Symbol;color:#1F497D'><span
style='mso-list:Ignore'>&middot;<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; \
color:#1F497D'>ActionEvaluator.g3 (and the generated \
ActionEvaluator.cs)<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l2 level1 lfo3'><![if \
!supportLists]><span style='font-size:11.0pt;font-family:Symbol;color:#1F497D'><span
style='mso-list:Ignore'>&middot;<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; \
color:#1F497D'>ActionEvaluatorHelper.cs<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l2 level1 lfo3'><![if \
!supportLists]><span style='font-size:11.0pt;font-family:Symbol;color:#1F497D'><span
style='mso-list:Ignore'>&middot;<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; \
color:#1F497D'>ASTExpr.cs<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l2 level1 lfo3'><![if \
!supportLists]><span style='font-size:11.0pt;font-family:Symbol;color:#1F497D'><span
style='mso-list:Ignore'>&middot;<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
</span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; \
color:#1F497D'>ConditionalExpr.cs<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Both of the compilation techniques produced good performance \
results.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<table class=MsoTableLightShadingAccent1 border=1 cellspacing=0 cellpadding=0
 style='border-collapse:collapse;border:none'>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'><o:p>&nbsp;</o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Ported \
Java<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Functors<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>DynamicMethod<o:p></o:p></span></b></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Maintainability<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Excellent<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Good<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Poor<o:p></o:p></span></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Debugging<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Excellent<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Very \
good<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Poor<o:p></o:p></span></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Parse and \
compile time<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Good<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Excellent<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Poor*<o:p></o:p></span></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Memory \
usage<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Moderate<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Good**<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;padding:0in 5.4pt 0in \
5.4pt'>  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Excellent<o:p></o:p></span></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Execution \
time<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Poor<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>Very \
good<o:p></o:p></span></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border:none;background:#D3DFEE;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>Excellent***<o:p></o:p></span></p>  </td>
 </tr>
 <tr>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  color:#1F497D'>The \
Grade<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>16<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>19<o:p></o:p></span></b></p>  </td>
  <td width=160 valign=top style='width:119.7pt;border-top:solid #4F81BD 1.0pt;
  border-left:none;border-bottom:solid #4F81BD 1.0pt;border-right:none;
  padding:0in 5.4pt 0in 5.4pt'>
  <p class=MsoNormal><b><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";  \
color:#1F497D'>13<o:p></o:p></span></b></p>  </td>
 </tr>
</table>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>* This should be avoided by parsing once and GetInstanceOf for each
usage. It&#8217;s so slow that it makes DynamicMethod the slowest overall
technique for minimal-reuse templates (1-10? usages maybe).<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>** I haven&#8217;t evaluated how functor caching affects \
this.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>*** This is an asymptotic characteristic for high-reuse \
templates.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>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:<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo2'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Define the \
</span><span style='font-size:8.0pt;font-family:Consolas'>COMPILE_EXPRESSIONS</span><span
 style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>
build macro.<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo2'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Optionally \
define the </span><span style='font-size:8.0pt; \
font-family:Consolas'>CACHE_FUNCTORS</span><span style='font-size:11.0pt; \
font-family:"Calibri","sans-serif";color:#1F497D'> build macro. I believe it would \
provide good results if you are caching your templates, but might leak memory over \
time.<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo2'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Set \
</span><span style='font-size:8.0pt;font-family:Consolas'>ASTExpr.EnableDynamicMethods
 = <span style='color:blue'>false</span></span><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>. (This is the \
default.)<o:p></o:p></span></p>

<p class=MsoListParagraph style='text-indent:-.25in;mso-list:l1 level1 lfo2'><![if \
!supportLists]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><span \
style='mso-list:Ignore'>4.<span style='font:7.0pt "Times New \
Roman"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><![endif]><span \
style='font-size:11.0pt;font-family:"Calibri","sans-serif"; color:#1F497D'>Set \
</span><span style='font-size:8.0pt;font-family:Consolas'>ASTExpr.EnableFunctionalMethods
 = <span style='color:blue'>true</span></span><span style='font-size:11.0pt;
font-family:"Calibri","sans-serif";color:#1F497D'>. (This is the \
default.)<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>There was long thread (subject &#8220;StringTemplate Compiler
for .NET&#8221;, Feb. 28 &#8216;09 through Apr. 1 &#8216;09) on this list
talking about how to further optimize ST, but I haven&#8217;t implemented several
of the items discussed. I&#8217;m planning on traveling to USF in late July for
a brainstorming session on future ANTLR/ST optimization.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Sam<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span \
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> \
stringtemplate-interest-bounces@antlr.org \
[mailto:stringtemplate-interest-bounces@antlr.org] <b>On Behalf Of </b>Graham \
Brooks<br> <b>Sent:</b> Thursday, June 18, 2009 9:48 AM<br>
<b>To:</b> stringtemplate-interest@antlr.org<br>
<b>Subject:</b> [stringtemplate-interest] String template \
compiler<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>All,<o:p></o:p></p>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>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.<o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>Thanks in advance...<o:p></o:p></p>

</div>

<div>

<div>

<div>

<div>

<div>

<div>

<p class=MsoNormal><span class=apple-style-span><i><span style='font-size:18.0pt;
font-family:"Brush Script MT";color:black'>Graham</span></i></span><span
style='font-size:9.0pt;font-family:"Arial","sans-serif";color:black'><o:p></o:p></span></p>


</div>

</div>

</div>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</div>

</body>

</html>



_______________________________________________
stringtemplate-interest mailing list
stringtemplate-interest@antlr.org
http://www.antlr.org/mailman/listinfo/stringtemplate-interest

--===============3794425422983411538==--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic