4

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?

Fixpoint
  • 9,619
  • 17
  • 59
  • 78
  • Not a cache problem? What if you cached the resultant String? – Mark Peters Jun 23 '10 at 15:40
  • This is what I'm planning to do to fix the problem temporarily, but I'd prefer a fast view engine to caching. – Fixpoint Jun 23 '10 at 17:13
  • @Fixpoint: Could you please post sourcecode you are using to benchmark ST? – Vladimir Sitnikov Mar 22 '12 at 12:09
  • The code isn't accessible to me any more, unfortunately (I left the company). Another important issues became a priority then and I couldn't get back to investigating this problem. – Fixpoint Mar 22 '12 at 12:42
  • I'll accept Terrence's answer, since it could be of use for other people discovering this question. And also because he's the author. – Fixpoint Mar 22 '12 at 12:42

3 Answers3

4

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

Terence Parr
  • 5,912
  • 26
  • 32
1

If you use toString() Memory is going to large.

Check your memory when run load test with toString() case.

If your memory is enough. Two case is the same time.

Florent
  • 12,310
  • 10
  • 49
  • 58
Thanh Tung
  • 95
  • 1
  • 3
1

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
  • 44,725
  • 9
  • 65
  • 93
  • 1
    I've just measured (1) and (2). Unfortunately, the problem is in `toString`; `print` takes very little time. – Fixpoint Jun 24 '10 at 13:28