Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Very Slow Fields Cut

Hi everyone, 
I'm trying to cut across all fields sets and gets in my class but aspectj is
delivering very low performance even while I'm just directly calling the
proceed() in the point cut. 

I created 2 classes, one with aspectj (SuperCar) and one just POJO (Car) the
SuperCar has a pointcut in  all the fields (for now only the “model” field
).

////////////////////////////////////////////////////////
public class Car {
    private int model=0;
    public int getModel() {
        return model;
    }
    public void setModel(int model) {
        this.model = model;
    }    
}

////////////////////////////////////////////////////////

/**
* This will cut all get & set in the SuperCar ( But as you can see that I'm
doing nothing only passing it again using proceed )
*/
public privileged aspect SuperObjectController{
    pointcut getProperty(SuperObject o): this(o) && get(@SuperProperty * *)
&& target(SuperObject+);
    Object around(SuperObject o):      
    getProperty(o) 
    {
        return proceed(o); 
    }
    pointcut setProperty(SuperObject o,Object v): this(o) && args(v) &&
set(@SuperProperty * *) && target(SuperObject+) ;
    void around(SuperObject o,Object v):      
    setProperty(o,v) 
    {
        proceed(o,v); 
    }
}

///////////////////////////////////////////////////////

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)

public @interface SuperProperty {
    boolean ensureGroupValue() default false;
}

/////////////////////////////////////////////////////
public class SuperObject {
}
/////////////////////////////////////////////////////
public class SuperCar extends SuperObject{
    @SuperProperty private int model=0;

    public int getModel() {
        return model;
    }

    public void setModel(int model) {
        this.model = model;
    }

}
///////////////////////////////////////////////////////
public static void main(String[] args) {
        // TODO code application logic here
        int LOOP=1000000;
        long lastTime,currentTime;
        int out;
        lastTime=System.currentTimeMillis();
        SuperCar superCar=new SuperCar();
        superCar.setModel(0);
        for (int i=0;i<LOOP;i++){
            //Set
            superCar.setModel(i);
            //Get
            out=superCar.getModel();
        }
        currentTime=System.currentTimeMillis()-lastTime;
        System.out.println("Super:"+currentTime);
        lastTime=System.currentTimeMillis();
        Car car=new Car();
        for (int i=0;i<LOOP;i++){
            //Set
            car.setModel(i);
            //Get
            out=car.getModel();
        }
        currentTime=System.currentTimeMillis()-lastTime;
        System.out.println("Normal:"+currentTime);
}
///////////////////////////////////////////////////////
this is the output for both classes.

Super:414
Normal:35

As you can see that the Super toke 0.414 second  to set and get while the
POJO toke only 0.035 , I don't understand why aspectj it to slow ? How it's
being compile ? 

POJO  is about 11.4 times faster without aspectJ cuts. I was thinking it
would be 50% slower for the extra call but not 8 % !.


Thanks in advance
-- 
View this message in context: http://www.nabble.com/Very-Slow-Fields-Cut-tp17139141p17139141.html
Sent from the AspectJ - users mailing list archive at Nabble.com.



Back to the top