In ST.toString(), I create a new StringWriter every time I render a template to string:
public String toString(int lineWidth) {
StringWriter out = new StringWriter();
// Write the output to a StringWriter
StringTemplateWriter wr = group.getStringTemplateWriter(out);
...
Worse, that getStringTemplateWriter() call creates a new AutoIndentWriter each time. For very large and highly nested output structures with lots of embedded STs, many many of these object will be created. Worse, there is a lot of data copying from one StringWriter to another as it includes all of the embedded templates together.
Find a way to reuse a single string writer for the whole system and use a Singleton AutoIndentWriter. Should be easy by using write(aSharedAutoIndentWriter). There may be some issues with the line wrap and indentation state.
Comments (1)
Nov 09, 2006
Kay Röpke says:
this is ST-4: http://www.antlr.org:8888/browse/ST-4this is ST-4: http://www.antlr.org:8888/browse/ST-4