开发者

StringTemplate bad performance

I'm using StringTemplate to generate some xml files from datasets. Sometimes I have more than 100,000 records in the dataset that is enumerated by a loop in a template. It goes very slow (15-20 secs per operation) so performance is not good for me.

This is an example how I use ST to render a report:

using (var sw = new StringWriter())
{
 st.Write(new StringTemplateWriter(sw));
 return sw.ToString();
}

StringTemplateWriter is a simple writer-class derived from IStringTemplateWriter without indentation.

By the way, in the debug screen I see a lot of such weird message:

"A first chance exception of type 'antlr.NoViableAltException' occurred in StringTemplate.DLL"

in a deep of debug I found that it parses my template recursively and if something failed (don't know what exactly) it throws NoViableAltException exception to return from a deep of stack back to a surface, so I guess the problem is in 开发者_运维技巧using of too much try-catch-throw's.

Google found nothing useful on this.

Main question: how to decrease this number of exceptions (except rewriting the code of ST) and improve performance of template rendering?


ST parses ST templates and groups with ANTLR. If you are getting syntax errors, your template(s) have errors. All bets are off for performance as it throws an exception for each one. ANTLR/ST not at fault here ;) Terence


NoViableAltException sounds like a parser error. I am not sure why ANTLR is being used (except that they come from the same author), but the only guess I can come up with is that the template language itself is parsed using ANTLR. Maybe the template contains errors? Anyway ANTLR's error handling is really slow (for one, it uses exceptions) so that's probably why your template expansion is slow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜