Anyone knows how expensive would it be to cfinclude a .cfm of many functions into a CFC?
<cfcomponent>
<cfinclude template="functions.cfm">
Or would it be faster if I attach functions to the object directly into its This scope? (func1, func2 would be functions of the singleton Factory object).
<cffunction name="createX">
<cfset x = new X()>
<cfset x.func1 = func1>
<cfset x.func2 = func2>
Which one is more efficient in terms of performance and memory usage?
Actually, how efficient is cfinclude? Would the code be compiled on every include?
Short response suitable for StackOverflow:
You need to remember that it’s not the CFML that gets executed, so for performance considerations the more significant thing to look at is what ColdFusion actually executes, which is the compiled class files. And when compiling a CFC, CF creates one class for the CFC itself, and one class per method in the CFC. This is the same whether the methods are inline or included separately. The contents of the classes are slightly different, but not in a way that’s meaningful as far as performance is concerned.
There are further considerations though, which favour – IMO – just putting the methods into the CFC.
Longer answer:
I’ve posted a larger analysis (which strays off-topic for your question, so not entirely suitable for here) on my blog, over here…