Skip to main content

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

Ok, I made the changes as you outlined. And did another run (1.6VM) -
I up'd the loop to 10,000,000 from 1,000,000 as I was getting 0's for
some measurements.
Iteration: 1
Super:234
Normal:9
Non-Direct:229
Iteration: 2
Super:229
Normal:2
Non-Direct:234
Iteration: 3
Super:195
Normal:2
Non-Direct:227


I then changed your aspect to use the field type rather than Object
(which removes the need for a type conversion):
Iteration: 1
Super:31
Normal:18
Non-Direct:216
Iteration: 2
Super:34
Normal:2
Non-Direct:240
Iteration: 3
Super:2
Normal:1
Non-Direct:239

Here is the new aspect:

public privileged aspect SuperObjectController{

   pointcut getProperty(SuperObject o): this(o) && get(@SuperProperty
* *) && target(SuperObject+);
   int around(SuperObject o): getProperty(o) {
       return proceed(o);
   }

   pointcut setProperty(SuperObject o,int v): this(o) && args(v) &&
set(@SuperProperty * *) && target(SuperObject+) &&
!within(SuperObjectController);;
   void around(SuperObject o,int v): setProperty(o,v) {
       proceed(o,v);
   }
}

Andy



2008/5/9 nnaass <alaamurad@xxxxxxxxx>:
>
> Hey Andy ,
>
> First thanks for the quick responds. I'm glad that my post made sense to
> somebody. I understand the different between the cold and hot. but I still
> don't understand why is the pointcut is too expensive. let me alter the Car
> class like this:
>
> /////////////////////////////////////////////
> public class Car {
>
>    private int model=0;
>
>    public int getModel() {
>        return model;
>    }
>
>    public void setModel(int model) {
>        this.model = model;
>    }
>
>    public void setProperty(String s,Object o){
>        if (s.equals("model")){
>            setModel((Integer)o);
>        }
>    }
>
>    public Object getProperty(String s){
>        if (s.equals("model")){
>            return getModel();
>        }else{
>            return null;
>        }
>    }
> }
>
> /////////////////////////////////////////////////
> Then add this to the main (benchmark) ,as you can see I'm accessing the
> 'model' through string (just to make the non-direct call)
>
>            Car car2 = new Car();
>            for (int i = 0; i < LOOP; i++) {
>                //Set
>                car2.setProperty("model", i);
>                //Get
>                out = (Integer) car2.getProperty("model");
>            }
>            currentTime = System.currentTimeMillis() - lastTime;
>
>            System.out.println("Non-Direct:" + currentTime);
>
> ////////////////////Now here are the results //////////////////////////
> Super:157
> Normal:28
> Non-Direct:92
> Super:117
> Normal:24
> Non-Direct:62
> Super:137
> Normal:25
> Non-Direct:51
>
>
> And this what I though the AspectJ pointcut will cost just twice the speed
> but as you can see that the Normal Car class is running (5.48) times faster.
> this is a lot, especially that this is cutting fields (will be accessed
> millions of times).
>
> I need a high performance AOP. I guess I need to look at the javassist to
> because I could add the pointcut with only 50% performance loss.
>
> it would be nice if people that understand the AspectJ compiler explain to
> me why it's taking that long for the pointcut .
>
> Thanks
>
>
>
> Andy Clement wrote:
>>
>> I've just tried your program, first on a 1.5 VM.   I also changed your
>> benchmark code to do the run three times in the main() method so the
>> JIT has a chance to be 'warmed up' with the code paths.
>>
>> Super:106
>> Normal:16
>> Super:80
>> Normal:16
>> Super:82
>> Normal:16
>>
>> I then tried it with a 1.6VM:
>> Super:63
>> Normal:9
>> Super:33
>> Normal:9
>> Super:32
>> Normal:9
>>
>> Not brilliant, I know, but not as bad as you seem to be seeing.  Even
>> though you are only doing proceed() from your advice at the moment,
>> the code is all in place for obtaining the aspect instance at each
>> join point and then invoking the advice.  So if you did more in your
>> advice body, it won't be a further large performance impact, it is
>> purely getting to the advice that is the big impact.  For the case
>> where proceed() is all you do in the advice we could optimize it all
>> away and do no weaving, but that is the rather uncommon case...
>>
>> cheers,
>> Andy.
>>
>> 2008/5/9 nnaass <alaamurad@xxxxxxxxx>:
>>>
>>> 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.
>>>
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Very-Slow-Fields-Cut-tp17139141p17157297.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top