Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

Performance testing the onMissingHandler method

June 18, 2007 ·

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!

Tags: coldfusion · webdev

7 responses

  • 1 pan69 // Sep 22, 2008 at 4:11 PM

    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.
  • 2 Sean Corfield // Sep 22, 2008 at 4:11 PM

    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.
  • 3 Ben Nadel // Sep 22, 2008 at 4:11 PM

    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.
  • 4 Mark Drew // Sep 22, 2008 at 4:11 PM

    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!)
  • 5 Ashwin // Sep 22, 2008 at 4:11 PM

    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.
  • 6 Mark Drew // Sep 22, 2008 at 4:11 PM

    @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
    }
  • 7 Ashwin // Sep 22, 2008 at 4:11 PM

    Yes, something like that.