On Thu, Nov 11, 2010 at 8:36 PM, Matt Sergeant <matt@sergeant.org> wrote:

Another idea I had

IMHO we've already put *far* more effort into this than is warranted for old code that's I hope to make obsolete soon anyway. So, to keep things moving forward I'm making an Executive Decision. :-)

Let's keep the code that's currently committed, with one minor change - where it currently caches all methods that get caught by the autoload, it will instead check $isSuperMethod, and only cache methods that were *not* called with SUPER::foo(). Given typical usage patterns, that means your cache code will be able to improve performance for the huge majority of method calls - probably 95% or better. That's a huge win.

In all of the CamelBones examples, the string "->" appears 755 times, and "->SUPER::" only three times, in initializer methods that are only called once in an object's lifetime. Let's not get too bogged down trying to figure out how to get that last tiny handful of method calls to cache as well - we've reached a point of diminishing returns here.

The worst-case scenario is when the same method is called both ways. I suspect that case is pretty darn rare in practice. There are no cases of it in any of the example code or self-tests. Say you have Objective-C class A. You create instances of A with A->alloc()->init(). You also have B, a Perl subclass of A. B's init calls SUPER::init(). So, A's -init gets called both ways. The workaround is easy -  just disable caching when you call A's init() directly:

    my $a;
        local $CamelBones::CacheAutoload = 0;
        $a = A->alloc()->init();

So, a *huge* majority of method calls get a significant performance boost, with only one very rare failure scenario that has an easy workaround. For ancient code that's due to be replaced soon anyway, I say we declare victory and move on.


Cocoa programming in Perl: