Soy templates and Servlets

706 views
Skip to first unread message

Prakash .

unread,
Nov 14, 2011, 7:05:32 PM11/14/11
to Closure Templates Discuss
Hi,

Thinking of using soy templates instead of jsp. Had a couple of
questions, any help is appreciated.

1. Is there any performance/hearsay data on Soy templates vs jsp?

2. I dont want to compile a SoyTofu object on every servlet request,
so i was thinking of shoving it in a static member? Will this work, is
the soytofu rendering thread agnostic? (that is can two renders happen
with the same tofu object in different threads at the same time?)

3. More a general knowledge question, does google internally use soy
templates in their servlet code? Any opensource project pointers?


Thanks,
-Prakash

Mike Samuel

unread,
Nov 15, 2011, 1:12:14 PM11/15/11
to closure-temp...@googlegroups.com
2011/11/14 Prakash . <prakas...@gmail.com>:

> Hi,
>
> Thinking of using soy templates instead of jsp. Had a couple of
> questions, any help is appreciated.
>
> 1. Is there any performance/hearsay data on Soy templates vs jsp?

Not to my knowledge. The most recent release has significant Java
backend performance improvements over the first release, so any
benchmarks done against the first release should be considered
obsolete.
http://code.google.com/p/closure-templates/source/detail?r=20

> 2. I dont want to compile a SoyTofu object on every servlet request,
> so i was thinking of shoving it in a static member? Will this work, is
> the soytofu rendering thread agnostic? (that is can two renders happen
> with the same tofu object in different threads at the same time?)

Yes. SoyTofu is thread-safe, but the renderers returned by newRenderer are not.

It was designed so that you can do

static final SoyTofu MY_COMPILED_TEMPLATE = ...;

and have many threads in parallel do

MY_COMPILED_TEMPLATE.newRenderer(....)....render()

> 3. More a general knowledge question, does google internally use soy
> templates in their servlet code? Any opensource project pointers?

Google does use closure templates internally.
Chapter 6 of http://www.cs.berkeley.edu/~prateeks/papers/csas-ccs11.pdf
has some publicly released stats:

"""
Closure Templates are used extensively in large web applications in-
cluding Gmail, Google Docs and other Google properties.

...

For real-world evaluation, we gath-
ered all Closure templates accessible to us. Our benchmarks
consist of 1035 distinct Closure templates from Google's
commericially deployed applications. The templates were
authored by developers prior to our CSAS engine implemen-
tation. Therefore, we believe that these examples represent
unbiased samples of existing code written in templating lan-
guages.
The total amount of code in the templates (excluding le
prologues and comments outside the templates) is 21; 098
LOC. Our benchmarks make heavy use of flow control con-
structs such as callTemplate calls. Our benchmark's tem-
plate call-graph is densely connected. It consists of 1035
nodes, 2997 call edges and 32 connected components of size
ranging from 2 - 12 templates and one large component with
633 templates.
"""

That case study is based on an analysis of Google code done some time
ago, and I can now say that Google+ is one of the projects that use
Closure templates.

I don't know of any survey of open source projects that use closure
templates, but http://www.google.com/codesearch#search/&q=import%20com.google.template.soy&type=cs
might help you find some pointers to projects that use the java
backend.


> Thanks,
> -Prakash

Prakash .

unread,
Nov 15, 2011, 2:32:22 PM11/15/11
to Closure Templates Discuss
Excellent. Thanks Mike.

On Nov 15, 10:12 am, Mike Samuel <mikesam...@gmail.com> wrote:
> 2011/11/14 Prakash . <prakashr.i...@gmail.com>:
>
> > Hi,
>
> > Thinking of using soy templates instead of jsp. Had a couple of
> > questions, any help is appreciated.
>
> > 1. Is there any performance/hearsay data on Soy templates vs jsp?
>
> Not to my knowledge.  The most recent release has significant Java
> backend performance improvements over the first release, so any
> benchmarks done against the first release should be considered
> obsolete.http://code.google.com/p/closure-templates/source/detail?r=20
>
> > 2. I dont want to compile a SoyTofu object on every servlet request,
> > so i was thinking of shoving it in a static member? Will this work, is
> > the soytofu rendering thread agnostic? (that is can two renders happen
> > with the same tofu object in different threads at the same time?)
>
> Yes.  SoyTofu is thread-safe, but the renderers returned by newRenderer are not.
>
> It was designed so that you can do
>
>    static final SoyTofu MY_COMPILED_TEMPLATE = ...;
>
> and have many threads in parallel do
>
>     MY_COMPILED_TEMPLATE.newRenderer(....)....render()
>
> > 3. More a general knowledge question, does google internally use soy
> > templates in their servlet code? Any opensource project pointers?
>
> Google does use closure templates internally.
> Chapter 6 ofhttp://www.cs.berkeley.edu/~prateeks/papers/csas-ccs11.pdf
> has some publicly released stats:
>
> """
> Closure Templates are used extensively in large web applications in-
> cluding Gmail, Google Docs and other Google properties.
>
> ...
>
> For real-world evaluation, we gath-
> ered all Closure templates accessible to us. Our benchmarks
> consist of 1035 distinct Closure templates from Google's
> commericially deployed applications. The templates were
> authored by developers prior to our CSAS engine implemen-
> tation. Therefore, we believe that these examples represent
> unbiased samples of existing code written in templating lan-
> guages.
> The total amount of code in the templates (excluding le
> prologues and comments outside the templates) is 21; 098
> LOC. Our benchmarks make heavy use of flow control con-
> structs such as callTemplate calls. Our benchmark's tem-
> plate call-graph is densely connected. It consists of 1035
> nodes, 2997 call edges and 32 connected components of size
> ranging from 2 - 12 templates and one large component with
> 633 templates.
> """
>
> That case study is based on an analysis of Google code done some time
> ago, and I can now say that Google+ is one of the projects that use
> Closure templates.
>
> I don't know of any survey of open source projects that use closure
> templates, buthttp://www.google.com/codesearch#search/&q=import%20com.google.templa...

Mike Samuel

unread,
Nov 15, 2011, 5:12:51 PM11/15/11
to closure-temp...@googlegroups.com
2011/11/15 Mike Samuel <mikes...@gmail.com>:

> That case study is based on an analysis of Google code done some time
> ago, and I can now say that Google+ is one of the projects that use
> Closure templates.

To add to this.
https://plus.google.com/u/0/115060278409766341143/posts/ViaVbBMpSVG :

"""
1. We <3 Closure

We like Closure. A lot. We use the Closure library, templates, and
compiler to render every element on every page in Google+ -- including
the JavaScript that powers these pages. But what really helps us go
fast is the following:

- Closure templates can be used in both Java and JavaScript to render
pages server-side and in the browser. This way, content always appears
right away, and we can load JavaScript in the background ("decorating"
the page, and hooking up event listeners to elements along the way)

...
"""

Reply all
Reply to author
Forward
0 new messages