[jboss-user] [JBoss Microcontainer Development] - JBoss Reflect Performance Javassist vs Introspection

Kabir Khan do-not-reply at jboss.com
Thu Apr 15 13:31:32 EDT 2010


Kabir Khan [http://community.jboss.org/people/kabir.khan%40jboss.com] replied to the discussion

"JBoss Reflect Performance Javassist vs Introspection"

To view the discussion, visit: http://community.jboss.org/message/537798#537798

--------------------------------------------------------------
I have done some performance measurements where I compare the times taken creating the following class, using javassist.bytecode.* and asm

 
public class JavassistMethod1 implements JavassistMethod
{ 
  public Object invoke(Object target, Object[] args) throws Throwable
  {     
      return Integer.valueOf(((SomeClass)target).someMethod(((Integer)args[0]).intValue(), (String)args[1])).intValue();
  }
} 

 
 
Which would be used to call the method:
    int someMethod(int i, String);

 
 
The basic flow for what I do for both approaches is the same, whereby I do the following lots of times to generate lots of similar classes:
 
 
A) - Create class structure
B) - Add default constructor with body to call super
C) - Add invoke method
C1) - Add invoke method body
D) - Convert class structure from A) into byte[]
E) - Define java.lang.Class by calling ClassLoader.defineClass()
F) - Call Class.newInstance() 
 
 
 
1 - Average times (ms) to do A-F is:
|| *Classes* || *ASM* || *Javassist* || *ASM/Javassist* ||
| 10000 | 1079 | 1585 | .68 |
| 15000 | 1550 | 2153 | .72 |
| 20000 | 1901 | 2665 | .71 |

 
 
2 - Taking the instantiation out of the equation, so we just do A-E:
|| *Classes* || *ASM* || *Javassist* || ASM/Javassist ||
| 20000 | 1290 | 1998 | .64 |

 
 
3 - Not loading the class, so we do A-D:
|| *Classes* || *ASM* || *Javassist* || *ASM/Javassist* ||
| 20000 | 391 | 1115 | .35 |
| 40000 | 499 | 1489 | .34 |

 
4 - Just doing A-C shows that javassist has a massive overhead in step D:
|| *Classes* || ASM || *Javsssist* || *ASM/Javassist* ||
| 40000 | 524 | 747 | .71 |
| 100000 | 823 | 1244 | .66 |

 
 
5 - Doing A-C with a simplified method body in C1 so it is just the equivalent of {return null;}:
|| Classes || *ASM* || *Javassist* || *ASM/Javassist* ||
| 40000 | 494 | 617 | .80 |
| 100000 | 723 | 923 | .78 |

 
6 - If I don't create the method in C at all, so I just do A-B 
|| *Classes* || ASM || Javassist || ASM/Javassist ||
| 40000 | 449 | 589 | .76 |
| 100000 | 619 | 845 | .73 |

 
 
So unfortunately Javassist is slower than ASM when it comes to creating new classes. Both at generating the bytecode, and a lot slower at converting the javassist.bytecode.ClassFile to a byte[].
 
The other overhead in this, as mentioned in a previous post, is the actual loading and instantiation of the classes themselves. So, I think generating less classes that do more stuff is the way forward, although that means a bigger overhead in creating the methods which will be bigger. I will play with creating an asm version of that.
 

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/537798#537798]

Start a new discussion in JBoss Microcontainer Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2115]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100415/0ad08589/attachment.html 


More information about the jboss-user mailing list