rip747 / Mustache.cfc

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

Remove regex caching: memory leak & Lambda evaluation refactor. #8

Closed markmandel closed 12 years ago

markmandel commented 12 years ago

This is actually 2 things:

1) Remove the regex caching. In our tests it was bringing down our servers with a memory leak. Doesn't seem to be giving us much major performance improvement anyway.

2) Move the lambda call into it's own method, so that it can be overwritten when extending Mustache.

dswitzer commented 12 years ago

Do you think it's worth changing the renderLambda() function from:

        <cfreturn evaluate("arguments.context.#arguments.tagName#(arguments.template)") />

To something like:

<cfset var local = {} />

<!---// if running on a component //--->
<cfif isObject(arguments.context)>
    <!---// call the function and pass in the arguments //--->
    <cfinvoke component="#arguments.context#" method="#arguments.tagName#" returnvariable="local.results">
        <cfinvokeargument name="1" value="#arguments.template#">
    </cfinvoke>
<!---// otherwise we have a struct w/a reference to a function or closure //--->
<cfelse>
    <cfset local.fn = arguments.context[arguments.tagName] />
    <cfset local.results = local.fn(arguments.template) />
</cfif>

<cfreturn local.results />

This removes the evaluate() from the code and might make things a little safer.

I can issue a pull request if you guys like the change. I have done any performance testing, so I'm not sure how it affects performance.

dswitzer commented 12 years ago

Oops... Here's the code:

<cfset var local = {} />

<!---// if running on a component //--->
<cfif isObject(arguments.context)>
    <!---// call the function and pass in the arguments //--->
    <cfinvoke component="#arguments.context#" method="#arguments.tagName#" returnvariable="local.results">
        <cfinvokeargument name="1" value="#arguments.template#">
    </cfinvoke>
<!---// otherwise we have a struct w/a reference to a function or closure //--->
<cfelse>
    <cfset local.fn = arguments.context[arguments.tagName] />
    <cfset local.results = local.fn(arguments.template) />
</cfif>

<cfreturn local.results />
dswitzer commented 12 years ago

Here's what the changes look like:

https://github.com/dswitzer/Mustache.cfc/commit/7424945125e514ff89e463bfc5d3b5b8ceb7937f

markmandel commented 12 years ago

Works for me. I have something similar in my extended version, where I pass in all the data and the context to the lamda (which is technically not in the Mustache spec, but is the only way to do caching in this CFML version)