Performance testing the onMissingHandler method

Posted At : June 18, 2007 6:21 AM | Posted By : Mark Drew
Related Categories: coldfusion, metrics

I was having a conversation with another developer at work about using the new CF8 onMissingHandler method for components. The issue we were debating was that in Java, using the try/catch or basically error trapping should be slighly more expensive than without it and if in-fact the onMissingMethod was trapping missing method errors, then there should be a big overhead, so it would mean that depending on it would't be a good thing.

From what I understand, when ColdFusion compiles CFML code down to Java, each of the functions doesn't get rendered to a java method, but rather to an inner class, so the onMissingMethod is actually another inner class so there should be no overhead.

I did a bunch of tests (Here is the code on the measurement and reporting) and it looks like that onMissingMethod is totally safe to use (performance wise)!

Another great reason to use CF8!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
pan69's Gravatar That doesn't seem to make a lot of difference. You could basically say that the Java class thats being generated always uses exceptions whether or not you specify the handler.
# Posted By pan69 | 6/18/07 7:15 AM
Sean Corfield's Gravatar It seems that the implementation for onMissingMethod() is wired into the method lookup code: method lookup is performed, if it fails, "onMissingMethod" lookup is performed, if that fails, an exception is thrown, else the matching method is called.

So, yes, onMissingMethod() is nice and performant.
# Posted By Sean Corfield | 6/18/07 8:21 AM
Ben Nadel's Gravatar Mark, thanks for doing that test. It is always good to know not just that we have these options, but that they are feasible to use.
# Posted By Ben Nadel | 6/18/07 11:30 AM
Mark Drew's Gravatar That was the whole point I think, even when you think that the code for the onMissingHandler is ACTUALLY setting something by doing some string manipulation and a switch, so its quite nice to see that there isnt a lot of slow down (if any!)
# Posted By Mark Drew | 6/18/07 12:17 PM
Ashwin's Gravatar Just to confirm what Sean said - the UDF objects are stored in a map internally, so it's a simple look up by method name, barely any overhead at all.
# Posted By Ashwin | 6/19/07 12:17 PM
Mark Drew's Gravatar @Ashwin: I thought that was how it handled it, the functions are rendered to separate Inner Classes right? Which are put in the HashMap, is it then a case of :

if(get("method") == null && get("onMissingMethod") != null){
run onMissingMethod
}
else {
throw exception
}
# Posted By Mark Drew | 6/20/07 6:49 AM
Ashwin's Gravatar Yes, something like that.
# Posted By Ashwin | 6/20/07 7:07 AM