rip747 / Mustache.cfc

{{ mustache }} for ColdFusion
http://mustache.github.com/
MIT License
46 stars 22 forks source link

Performance improvements #25

Closed daamsie closed 11 years ago

daamsie commented 11 years ago

Using cfsavecontent in renderArraySection as it's faster according to tests.

Creating java regex Pattern object only once

Replace partials into template at start to simplify the process.

daamsie commented 11 years ago

I made these changes because I was finding that looping over arrays and rendering partials was particularly slow. The following is the test code I was using to compare performance to old and new:

<cfset mypartial="this is the iteration number {{element}}">
<cfset template="This is a test template looping over a partial with {{count}} items in it {{##results}}{{>mypartial}}{{/results}}">

<cfset newMustache=new Mustache(
            partials={
                "mypartial"=mypartial
            }) />

<cfset oldMustache=new Mustache2(
            partials={
                "mypartial"=mypartial
            }) />

<cfset content={
                "count"=1000,
                "results"=[]
                    }>

<cfloop from="1" to="#content.count#" index="i">
    <cfset arrayAppend(content.results,{
                    "element"=i
                }) />
</cfloop>

<cftimer label="newMustache">
    <cfset result=newMustache.render(template,content)>
</cftimer>
<cftimer label="oldMustache">
    <cfset result2=oldMustache.render(template,content)>
</cftimer>

Times with newMustache are at least 4x as fast on my machine (Mac with CF9). Drops from 900ms to 200ms. Sometimes oldMustache was even 1500ms or more.

rip747 commented 11 years ago

awesome!!!!