Forum: Rails Spinoffs (closed, excessive spam) Template performance

Posted by Namotco (Guest)
on 2008-06-24 16:22
(Received via mailing list)
I'm writing some new code and I'm considering using the Template
functions of prototype.  I've never used Template before. Is this
function fast or would it be faster to return HTML from the server?
In particular for a table with 250 items.

Thanks for the advice!
Posted by Frederick Polgardy (Guest)
on 2008-06-24 16:31
(Received via mailing list)
How will you be building the table?  I assume you're weighing the 
difference
between returning HTML from the server, and returning something like 
JSON
from the server and building the table in JS?  I'd say building a 250 
row
table in JS with a Template will be plenty fast (will be noticeably 
faster
than a DOM builder), and you can probably take advantage of some code 
reuse
if you want to add/remove/reorder table rows dynamically.  If the table 
is
going to remain relatively static, probably no need to bother doing it 
on
the client side.

-Fred

On Tue, Jun 24, 2008 at 9:21 AM, Namotco <namotco@gmail.com> wrote:

>
> I'm writing some new code and I'm considering using the Template
> functions of prototype.  I've never used Template before. Is this
> function fast or would it be faster to return HTML from the server?
> In particular for a table with 250 items.


--
Science answers questions; philosophy questions answers.
Posted by Namotco (Guest)
on 2008-06-24 21:09
(Received via mailing list)
I am planning to add/remove/change rows dynamically with a JSON
object.  I will need to create a new template if I want to change how
many rows there will be though, correct?
Posted by Frederick Polgardy (Guest)
on 2008-06-24 21:16
(Received via mailing list)
Use one template for the rows inside a loop, and then wrap it in a 
<table>.

-Fred

On Tue, Jun 24, 2008 at 2:08 PM, Namotco <namotco@gmail.com> wrote:

>
> I am planning to add/remove/change rows dynamically with a JSON
> object.  I will need to create a new template if I want to change how
> many rows there will be though, correct?


--
Science answers questions; philosophy questions answers.
Posted by Ken Snyder (Guest)
on 2008-06-24 23:05
(Received via mailing list)
Namotco wrote:
> I'm writing some new code and I'm considering using the Template
> functions of prototype.  I've never used Template before. Is this
> function fast or would it be faster to return HTML from the server?
> In particular for a table with 250 items.
>
> Thanks for the advice!
A few years ago I created a compile template class that compiles a
template so that it can be evaluated very quickly.  It is great for
these situations where you are creating html from json.

Check out the source with a table example at the end.

http://pastie.org/221410

You may also notice that it supports complex Smarty-like constructs such
as {if} and {foreach} and allows you to write more handlers for custom 
tags.

- Ken Snyder
Posted by kangax (Guest)
on 2008-06-25 01:24
(Received via mailing list)
Ken,
pre-instantiating prototype's Template is actually relatively fast
(vs. just using #interpolate on a string)
Have you, by any chance, done any benchmarking?

- kangax
Posted by Ken Snyder (Guest)
on 2008-06-25 16:34
(Received via mailing list)
kangax wrote:
> Ken,
> pre-instantiating prototype's Template is actually relatively fast
> (vs. just using #interpolate on a string)
> Have you, by any chance, done any benchmarking?
>
> - kangax
>   
I've done no benchmarking since the main functionality I wanted was if
and foreach.  But I'd be surprised if the eval() approach wasn't
significantly faster than the gsub() approach.  I've got a new version
in the works so I'll have to do some benchmarking.

- Ken
This topic is locked and can not be replied to.