Hello ST lovers,<br><br>I met StringTemplate about two years ago and before that i had never used a templating language (considering my 15+ years coding history, its a shame :), other than String.Format. Now, i have a CMS developed in C#/.NET that completely depends on ST to generate pages, where templates are stored in a SQL database. It is actively being used in some important web sites in my country. I love the idea behind ST to enforce model-view separation, which cleared the messy HTML markup from my C# classes completely, and made it easier to change the look of interface based on customer requests. I strongly recommend ST to any .NET developer. Even MS has seen the light and invented MVC framework but they are a bit late. Anyway, ST can be used as an alternative view engine in MVC framework too, as the default one doesn&#39;t still seem functional enough to me :)<br>
<br>Nowadays, i am working on a high traffic web site where we expect to take thousands of requests per second. A page with a rather complex template (or set of templates) takes about 35 ms (after some optimizations, it was 130 ms at start) just for StringTemplate.ToString(). This time doesn&#39;t include the time required to parse a template (templates are parsed and cached, and i&#39;m using ST.GetInstanceOf()), and it also doesn&#39;t include the time for populating template with data. Fetching all data required in the page from SQL and setting them in ST takes only 6 ms. <br>
<br>At first sight, 35 ms may seem a small amount of time, but it means that only about 25 requests per second can be handled by the web server if we had just called ST.ToString() to render a page, so the actual requests per second is even lower.<br>
<br>As i had no intention to give up on StringTemplate, decided to try writing a compiler for it. I&#39;ve set up a project in Google code. <br><br><a href="http://code.google.com/p/stringtemplate-dotnet-compiler/">http://code.google.com/p/stringtemplate-dotnet-compiler/</a><br>
<br>There is a working compiler in SVN repository, but don&#39;t expect much from it. It is only two days of work yet, not even in alpha state.<br><br>For now, it can only compile templates like &quot;testing $a:{$it:{$it:{$it:{$it$}$}$}$}$ $a+b+&quot;blablalalbla&quot;$ $b$ $c$ $d$ end&quot;<br>
<br>No formal arguments, no groups, no format/anchor/null options, no no no, just what you see above :)<br><br>When it comes to speed, for this simple template it works about 5 times faster than native StringTemplate. I&#39;m expecting the difference to grow as templates gets more complex. <br>
Also, there are some room for optimizations, such as inlining simple template chunks and constant expressions, but my priority is to create a fully compilant, working compiler.<br><br>To keep compiler simple, and easier to develop, i decided not to parse templates myself, but take a StringTemplate object, walk its chunks and trees and emit IL code instead of evaluating expressions. For example, i took ActionEvaluator.cs from ST source code, and replaced evaluation expressions with dynamic IL generating code. Result can be seen in ActionCompiler.cs.<br>
<br>I&#39;d appreciate any suggestions, ideas, help etc. Would like to hear from Terrence (thanks a lot for letting me see the light :), opinion as i read in the group he also has plans to turn StringTemplate into a code generating compiler in v4.<br>
<br>Volkan Ceylan<br><br><br><br><br><br><br><br><br>