Mustache benchmarks

50 views
Skip to first unread message

molte

unread,
Mar 18, 2010, 4:13:54 PM3/18/10
to Guardians of the Temple
Do you have any benchmarks on the Temple version of Mustache compared
to the "official" version at http://github.com/defunkt/mustache?

Magnus Holm

unread,
Mar 18, 2010, 4:43:06 PM3/18/10
to guardians-o...@googlegroups.com
Nope. That said, I wrote the current compiler which is used in defunkt's Mustache and the Temple version is pretty much a direct port (except that defunkt's compiles to a single, interpolated string so I expect it to be faster, if only by a fraction).

The Temple version of Mustache is actually more a proof-of-concept and will probably be removed in the future. At the moment Mustache is too simple to actually gain so much from Temple. I'm currently experimenting with compiling the core abstraction into JVM bytecode on JRuby (which hopefully should speed up rendering time). If Temple can show off such types of optimizations it's probably more tempting to write even simple template engines on top of Temple.

// Magnus Holm


On Thu, Mar 18, 2010 at 21:13, molte <mol...@gmail.com> wrote:
Do you have any benchmarks on the Temple version of Mustache compared
to the "official" version at http://github.com/defunkt/mustache?

To unsubscribe from this group, send email to guardians-of-the-temple+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Chris Wanstrath

unread,
Mar 18, 2010, 8:31:41 PM3/18/10
to guardians-o...@googlegroups.com
Mustache's "parser" is very naïve and can get confused in complicated
situations. I'd like to see if Temple can help out in those areas.

I've recently begun working on Mustache again and am in the process of
collecting a few test cases to begin experimenting with.

Basically, in other words, anything Magnus does that in any way
improves Mustache will be pulled into the official version because he
is awesome.

Chris

--
Chris Wanstrath
http://github.com/defunkt

Magnus Holm

unread,
Mar 19, 2010, 7:25:44 AM3/19/10
to guardians-o...@googlegroups.com
I think Mustache can gain more from Temple The Philosophy (keep parser/generator separated etc), than Temple The Library.

Here's a more solid Mustache parser (using StringScanner): http://gist.github.com/337428, including improved syntax error messages:

parser.rb:155:in `error': Unclosed tag (MustacheParser::SyntaxError)
  Line 1
    {{this tag only allows \w+}}
          ^

parser.rb:155:in `error': Unclosed section "testing" (MustacheParser::SyntaxError)
  Line 1
    {{#testing}}
             ^

parser.rb:155:in `error': Unclosed tag (MustacheParser::SyntaxError)
  Line 1
    {{! Comments can contain everything except newlines:
                                                       ^


// Magnus Holm

Magnus Holm

unread,
Mar 19, 2010, 8:02:51 AM3/19/10
to guardians-o...@googlegroups.com
Added a simple generator too: http://gist.github.com/337428 (and realized that comments can actually contain newlines).

Just `require "inject"` after Mustache is loaded, and it injects itself. When I added that to lib/mustache.rb, all tests pass except for two:

* test_unclosed_sections_reports_the_line_number (because it's "Line" and not "line" now)
* test_reports_unclosed_sections (because the class is MustacheParser::SyntaxError)

// Magnus Holm

Molte

unread,
Mar 20, 2010, 5:16:12 AM3/20/10
to guardians-o...@googlegroups.com
I understand. Thank you for answering.
----
Molte

CosSinCalc
http://cossincalc.com


2010/3/19 Magnus Holm <jud...@gmail.com>

Chris Wanstrath

unread,
Mar 23, 2010, 4:16:04 PM3/23/10
to guardians-o...@googlegroups.com
On Fri, Mar 19, 2010 at 4:25 AM, Magnus Holm <jud...@gmail.com> wrote:

> I think Mustache can gain more from Temple The Philosophy (keep
> parser/generator separated etc), than Temple The Library.
>
> Here's a more solid Mustache parser (using
> StringScanner): http://gist.github.com/337428, including improved syntax
> error messages:
>
> parser.rb:155:in `error': Unclosed tag (MustacheParser::SyntaxError)
>   Line 1
>     {{this tag only allows \w+}}
>           ^
>
> parser.rb:155:in `error': Unclosed section "testing"
> (MustacheParser::SyntaxError)
>   Line 1
>     {{#testing}}
>              ^
>
> parser.rb:155:in `error': Unclosed tag (MustacheParser::SyntaxError)
>   Line 1
>     {{! Comments can contain everything except newlines:
>                                                        ^
>
> // Magnus Holm

Wow, beautiful. I'll integrate this into Mustache proper as soon as I can.

Thanks! Mustachers the world over owe you a great debt.

Chris

Magnus Holm

unread,
Mar 23, 2010, 5:28:22 PM3/23/10
to guardians-o...@googlegroups.com
Not quite sure if it solves the problem you faced with the previous parser though (I don't really use Mustache), but hopefully it will be easier to fix those issues.

I'm also experimenting (in my head) with a Mustache generator with type-inference/where-the-value-comes-from-inference (so we don't need to do the slow @stack.each { }) which re-compiles itself as it knows more. It puts a few (but not too many IMO) limits on the template, but the performance would improve a lot.

// Magnus Holm


Chris Wanstrath

unread,
Mar 25, 2010, 7:29:07 PM3/25/10
to guardians-o...@googlegroups.com
On Tue, Mar 23, 2010 at 2:28 PM, Magnus Holm <jud...@gmail.com> wrote:

> Not quite sure if it solves the problem you faced with the previous parser
> though (I don't really use Mustache), but hopefully it will be easier to fix
> those issues.

It's awesome. Many issues have been fixed - thank you!

> I'm also experimenting (in my head) with a Mustache generator with
> type-inference/where-the-value-comes-from-inference (so we don't need to do
> the slow @stack.each { }) which re-compiles itself as it knows more. It puts
> a few (but not too many IMO) limits on the template, but the performance
> would improve a lot.

Great, can't wait to check it out.

Chris

Reply all
Reply to author
Forward
0 new messages