views:

127

answers:

1

I'm noticing terrible speeds when trying to use CGLIB with a callback filter (on tens of thousands of objects) but I'm unable to find any information about optimizing CGLIB.

For a search/list interface, the system is loading multiple properties from an optimized query and populating the domain tree with those properties. For all other properties, the LazyLoader is loading the full object. The idea is to have the basic properties used by the search/list to load, while not losing the domain model classes.

Basic Example

String name = rst.getString(1);

Enhancer enhancer = new Enchancer();
enhancer.setSuperclass(Type.class);
enhancer.setCallbackFilter(new CallbackFilter(){
    public int method(Method method){
        if("getName".equals(method.getName()){
            return 1;
        }
        return 0;
    }
});
enhancer.setCallbacks(new Callback[]{
    new LazyLoader(){...}
    new FixedValueImpl(name);
});
return (Type)enhancer.create()
A: 

It appears that if I set up the CallbackFilter as an instance variable instead of an anonymous inner class, the speed increases.

private CallbackFilter callbackFilter = new CallbackFilter(){...};

...

private Type createType(ResultSet rst){
    String name = rst.getString(1);

    Enhancer enhancer = new Enchancer();
    enhancer.setSuperclass(Type.class);
    enhancer.setCallbackFilter(this.callbackFilter);
    enhancer.setCallbacks(new Callback[]{
        new LazyLoader(){...}
        new FixedValueImpl(name);
    });
    return (Type)enhancer.create()
}
Jared Pearson