wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java reflection performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java reflection performance" Watch "java reflection performance" New topic
Author

java reflection performance

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
java reflection performance

Use java reflection to create an object , like Class.forName("fff").newInstance(), compared to regularly create an instance, how much it will downgrade the performance ? do we have a statistic chart ?

Thanks.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
why don't you just write a little piece of code that creates a million regular instances and then a milltion instances using reflections ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Edward Chen wrote:how much it will downgrade the performance ? do we have a statistic chart ?

by simple google, I find this. http://java.sun.com/docs/books/tutorial/reflect/index.html
from the same URL,
Performance Overhead Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.


http://muhammadkhojaye.blogspot.com/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Muhammad Khojaye wrote:
Edward Chen wrote:how much it will downgrade the performance ? do we have a statistic chart ?

by simple google, I find this. http://java.sun.com/docs/books/tutorial/reflect/index.html
from the same URL,
Performance Overhead Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.

Yes, that article does exist and can be found on the web. But it totally fails to answer Edward Chen's question about how much. Not to mention that the advice posted is unhelpful; if you have the choice to use either reflection or non-reflection, you should use the non-reflection version even if your application is performance-sensitive. Not only is it faster, but the code is easier to understand. And if you don't have the choice, you can't avoid using reflection, no matter whether the application is performance-sensitive or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java reflection performance
 
Similar Threads
Reg:use of interface in realtime environment
Justification of using Spring
To Dr.Forman, Objection Creation Issue in Java Reflection
Reflection: Performance vs Convenience
Reflection is a performance issue