On Friday, Nov 8, 2002, at 17:10 US/Pacific, Sean A Corfield wrote:
> So that's about a 2-3x factor for a UDF and a 10-11x factor for a CFC.
As someone pointed out, my math was bad and it was 100-110x. However...
> A CFC invocation is taking about 1.5ms - which isn't bad considering
> it's resolving the reference and calling out to another .class file
> with all the overhead you might expect on that sort of thing. It does,
> however, seem a little strange that the difference between a UDF and a
> CFC invocation is so dramatic. I'll ask some of the product team folks
> to comment.
I got an answer back that, when I thought about it some, made a lot of
sense.
First off, the 1 + 1 is effectively folded to a constant so that
calculation contributes nothing to the timing. Timing the inline code
therefore just times the loop and the simple assignment.
Next, the UDF calls. In order to call the UDF, CFMX has to 'lookup' one
symbol and call the function. Timing this code therefore times the
lookup and the call/return overhead.
Finally the CFC call. CFMX has to 'lookup' the instance name, then has
to 'lookup' the function inside the value of that instance (a struct
key dereference), set up 'this' scope for the instance and then call
the function. That's quite a bit of extra machinery over a simple
function call.
Since the contents of the functions - the original inline code - takes
a fairly negligible amount of time to execute, that amplifies the time
the other tasks take, as a percentage of the inline code. As I noted
above, the invocation is really only taking 1.5ms per call. If you have
a piece of code that takes, say, 3ms to execute and compare executing
it inline with executing it in a CFC method, the times would be as
follows for a 1000 iterations:
inline 3000ms
CFC 4500ms
Now we see that the CFC is only 1.5x slower. In the grand scale of
things, that's a relatively small price to pay for the benefits of the
abstraction and reusability you might gain from using a CFC.
Sean A Corfield -- Director, Architecture
Web Technology Group -- Macromedia, Inc.
tel: (415) 252-2287 -- cell: (415) 717-8473
aim: seancorfield -- http://www.macromedia.com
An Architect's View -- http://www.corfield.org/blog/
Introducing Macromedia Contribute. Web publishing for everyone.
Learn more at http://www.macromedia.com/contribute
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm