Bug Tracker

Opened 13 years ago

Closed 11 years ago

#8109 closed enhancement (invalid)

Meta: jQuery.tmpl Performance Issues

Reported by: Rick Waldron Owned by:
Priority: high Milestone: 1.next
Component: templates Version: 1.5
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by Rick Waldron)

Opening up discussion to document the improvement of jQuery.tmpl performance, as illustrated here:


Change History (10)

comment:1 Changed 13 years ago by Rick Waldron

Component: unfiledtemplates
Description: modified (diff)
Priority: undecidedhigh

comment:2 Changed 13 years ago by Rick Waldron

Status: newopen

comment:3 Changed 13 years ago by Rick Waldron

Description: modified (diff)

comment:4 Changed 13 years ago by BorisMoore

Perf is important, but perf comparisons are sometimes incorrect. The tests on the link are comparing how long each engine takes to render an HTML string. But for jQuery templates, they are using calling $.tmpl(template, data)- many times, which does not render an HTML string. It builds a jQuery object around a document fragment containing the rendered HTML ready for chaining with .appendTo. To use this without calling appendTo makes no sense, and will not perform well. It does much more than build an HTML string.

One of the goals of Beta2, planned for April, is to provide an API to allow you just to render an HTML string, if that is all you want. You can then innerHTML or .html(), for example to insert it. You can also render as a string on the server, and render that to the Response, for initial rendering. But there is also an activation step, which runs by default, and gives you tmplItem, and opens the way to all the interactive applications, if your app is not just read-only rendering. You can choose whether you want activation or not.

The current implementation uses a mix of string concatenation and document fragment instantiation, and does not provide an option for just rendering to a string. That has history going all the way back to the first prototype which John created, which this evolved from. See this issue, for related discussion: https://github.com/jquery/jquery-tmpl/issues/closed#issue/4. It links also to a discussion here: http://rileydutton.com/post/1303173205/jquery-templates-vs-jqote-2-a-followup-a-k-a-the%20%20

comment:5 Changed 13 years ago by BorisMoore

I have added a revision here to the perf comparison benchmark here: http://jsperf.com/dom-vs-innerhtml-based-templating/83, to correct some errors in the tests. The result is the jQuery Templates come out 12 times faster than the previous (misleading) results. The results are better than some of the other template engines, but fall quite a lot short of the fastest ones. That said, jQuery Templates does much more than those other fastest ones, (which are basically stripped down to minimal features for read-only rendering, no detection of functions, undefined, etc., with perf being in most cases their primary goal, I beleive.)

I think that the design changes in the pipeline for Beta2 will bring some signficant perf improvement for jQuery Templates, when used in read-only scenarios...

Version 0, edited 13 years ago by BorisMoore (next)

comment:6 Changed 12 years ago by john

Resolution: invalid
Status: openclosed

This should be moved over to the jQuery Templates bug tracker.

comment:7 Changed 12 years ago by BorisMoore

comment:8 Changed 11 years ago by Jeffery To

Resolution: invalidfixed

Fix #8109, percent animations; fix #11854, wrong this, close gh-808

Changeset: 801768386b9fd44f1282834449b4cd1ae1e8d593

comment:9 Changed 11 years ago by dmethvin

Resolution: fixed
Status: closedreopened

Ignore the message above, should have referenced #7109.

comment:10 Changed 11 years ago by dmethvin

Resolution: invalid
Status: reopenedclosed

This is not a jQuery Core ticket.

Note: See TracTickets for help on using tickets.