views:

82

answers:

2

I'm using StringTemplate as view layer for my web application. Recently I've measured how much time is spent rendering pages and it's around 50ms for simple pages and 500ms for complex pages. This is too much for my needs, so I'm looking for a way to improve ST's performance. How can I do this?

Most of the time is consumed by the StringTemplate.toString method, so it's not a cache problem.

I actively use anonymous templates and included templates - could this be the cause?

A: 

use write() not toString then writing to your stream. write() will render and transmit w/o buffering. big difference. Ter

Terence Parr
Could you clarify? Currently I'm doing this: `response.getWriter().print(template);`
Shooshpanchick
I've tried `template.write(new AutoIndentWriter(response.getWriter()));` - almost no improvement.
Shooshpanchick
really? For Java version that makes huge differ for large templates.
Terence Parr
You're not reloading templates each time, right?
Terence Parr
A: 

Is that the Terence Parr?

I think what Terence meant is

template.write(new AutoIndentWriter(response.getWriter()));

however I can not beieve that will make any noticeable difference.

You should time two things separately

String str = template.toString();  // 1
response.getWriter().print(str);   // 2

the slowness is probably on the 2nd line which involves IO.

irreputable
I've just measured (1) and (2). Unfortunately, the problem is in `toString`; `print` takes very little time.
Shooshpanchick