Why StringTemplate could be slow?

橙三吉。 提交于 2019-12-03 21:16:05

问题


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?


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3102971/why-stringtemplate-could-be-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!